PROJ icon indicating copy to clipboard operation
PROJ copied to clipboard

(Windows. Win32) Problem to add proj lib version 8.1.1 to Visual Studio 2019 Project

Open leosceint opened this issue 3 years ago • 1 comments

I made console C++ app in Visual Studio 2019. I include proj lib 8.1.1 to my project. I configure CMake to make library VS project to x86 platform. Lib was make as static lib. When I try build my project, I have such errors that linker can not find __imp__CoTaskMemFree@4 and _SHGetKnownFolderPath@16 symbol of functions.

As I understand, this functions used in filemanager of proj lib (core of lib). Tell me please, what settings of VS 2019 console project should have, so that the linker can find the paths in the static library to these functions. As additional dependecies I define curl, tiff, sqlite3. Such dependencies as ole32 and shell32 defined by default.

Thank you for help Leo

leosceint avatar Dec 13 '21 18:12 leosceint

These functions are in Shell32.lib and Ole32.lib. See https://docs.microsoft.com/en-us/windows/win32/api/combaseapi/nf-combaseapi-cotaskmemfree and related.

rhuijben avatar Jan 06 '22 15:01 rhuijben

I ran into the same problem, but with VS2022. Solved it using this change:

diff --git a/src/lib_proj.cmake b/src/lib_proj.cmake
index c49310f..33a6874 100644
--- a/src/lib_proj.cmake
+++ b/src/lib_proj.cmake
@@ -424,6 +424,13 @@ set_target_properties(proj
 set(PROJ_LIBRARIES proj)
 # hack, required for test/unit
 set(PROJ_LIBRARIES ${PROJ_LIBRARIES} PARENT_SCOPE)
+if (WIN32)
+target_link_libraries (proj
+  PRIVATE
+    shell32.lib
+    ole32.lib
+)
+endif (WIN32)
 if(UNIX)
   find_library(M_LIB m)
   if(M_LIB)

I am not sure if this is the best solution, if not please correct me. Thanks.

gitartpiano avatar Dec 03 '23 15:12 gitartpiano

I am not sure if this is the best solution, if not please correct me. Thanks.

that seems reasonable (although I'm not sure why we don't have errors related to that in our Windows continuous integration target). Do you want to do a pull request with that fix ? (you can drop the WIN32 in endif())

rouault avatar Dec 03 '23 15:12 rouault