[CMake] Clang + MinGW Linking Issue

Justin Holewinski justin.holewinski at gmail.com
Wed May 23 18:22:15 EDT 2012


Hi All,

I've been trying out CMake for building C++ applications on Windows with
Clang, using the MinGW headers/libraries.  This works fine, except if I
need to pull in non-default system libraries that are included with MinGW,
such as libpsapi.a (psapi.lib for VS).  For example, if I have the
following CMakeLists.txt file:

project(pstest1)
add_executable(pstest1 pstest1.cpp)
target_link_libraries(pstest1 psapi)


This fails with a linker error:

Linking CXX executable pstest1.exe
c:\projects\cmake-2.8.8-win32-x86\bin\cmake.exe -E cmake_link_script
CMakeFiles\pstest1.dir\link.txt --verbose=1
C:\projects\clang+llvm-3.1-i386-mingw32-EXPERIMENTAL\bin\clang++.exe
CMakeFiles/pstest1.dir/pstest1.obj  -o pst
est1.exe  *-lpsapi.lib*
*c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe:
cannot find -lpsapi.lib*
collect2: ld returned 1 exit status
clang++: error: linker (via gcc) command failed with exit code 1 (use -v to
see invocation)
mingw32-make[2]: *** [pstest1.exe] Error 1
mingw32-make[2]: Leaving directory `C:/projects/mingw-tests/pstest1/build'
mingw32-make[1]: *** [CMakeFiles/pstest1.dir/all] Error 2
mingw32-make[1]: Leaving directory `C:/projects/mingw-tests/pstest1/build'
mingw32-make: *** [all] Error 2


CMake seems to be using MSVC library naming conventions for Clang in MinGW
mode, but also using the GCC-style -l flags for specifying libraries.  If I
replace

target_link_libraries(pstest1 psapi)

with

target_link_libraries(pstest1 "c:/MinGW/lib/libpsapi.a")

then everything works as expected (I got -lpsapi on the link line).
 Interestingly, everything also works correctly if I use the default
mingw32-gcc.exe compiler instead of clang.exe.  So this seems to be a CMake
issue where it detects Clang but does not know how to properly pass
GCC-style linker flags to Clang.

Any ideas?


-- 

Thanks,

Justin Holewinski
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20120523/20aea65c/attachment.htm>


More information about the CMake mailing list