<div>Hi All,</div><div><br></div>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:<div>
<br></div><div><div><font face="'courier new', monospace">project(pstest1)</font></div><div><font face="'courier new', monospace">add_executable(pstest1 pstest1.cpp)</font></div><div><font face="'courier new', monospace">target_link_libraries(pstest1 psapi)</font></div>
<div><br></div><div><br></div><div>This fails with a linker error:</div><div><br></div><div><div><font face="'courier new', monospace">Linking CXX executable pstest1.exe</font></div><div><font face="'courier new', monospace">c:\projects\cmake-2.8.8-win32-x86\bin\cmake.exe -E cmake_link_script CMakeFiles\pstest1.dir\link.txt --verbose=1</font></div>
<div><font face="'courier new', monospace">C:\projects\clang+llvm-3.1-i386-mingw32-EXPERIMENTAL\bin\clang++.exe CMakeFiles/pstest1.dir/pstest1.obj -o pst</font></div><div><font face="'courier new', monospace">est1.exe <b>-lpsapi.lib</b></font></div>
<div><font face="'courier new', monospace"><b>c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find -lpsapi.lib</b></font></div><div><font face="'courier new', monospace">collect2: ld returned 1 exit status</font></div>
<div><font face="'courier new', monospace">clang++: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)</font></div><div><font face="'courier new', monospace">mingw32-make[2]: *** [pstest1.exe] Error 1</font></div>
<div><font face="'courier new', monospace">mingw32-make[2]: Leaving directory `C:/projects/mingw-tests/pstest1/build'</font></div><div><font face="'courier new', monospace">mingw32-make[1]: *** [CMakeFiles/pstest1.dir/all] Error 2</font></div>
<div><font face="'courier new', monospace">mingw32-make[1]: Leaving directory `C:/projects/mingw-tests/pstest1/build'</font></div><div><font face="'courier new', monospace">mingw32-make: *** [all] Error 2</font></div>
</div><div><br></div><div><br></div><div>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</div><div><br></div><div>
<span style="font-family:'courier new',monospace">target_link_libraries(pstest1 psapi)</span></div><div><br></div><div>with</div><div><br></div><div><span style="font-family:'courier new',monospace">target_link_libraries(pstest1 "c:/MinGW/lib/libpsapi.a")</span>
</div><div><br></div><div>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.</div>
<div><br></div><div>Any ideas?</div><div><br></div><div><br></div>-- <br><br><div>Thanks,</div><div><br></div><div>Justin Holewinski</div><br>
</div>