[CMake] Clang + MinGW Linking Issue

Justin Holewinski justin.holewinski at gmail.com
Thu May 24 12:22:57 EDT 2012


Hi Again,

I narrowed the problem down to Clang not having
Platform/Windows-Clang-{C,CXX}.cmake files.  If I add the following two
files then everything starts to work as expected:

Platform/Windows-Clang-C.cmake:

if(MINGW)
  include(Platform/Windows-GNU)
  __windows_compiler_gnu(C)
else()
  # Chain to generic Windows configuration
  include(Platform/Windows)
endif()

Platform/Windows-Clang-CXX.cmake:

if(MINGW)
  include(Platform/Windows-GNU)
  __windows_compiler_gnu(C)
else()
  # Chain to generic Windows configuration
  include(Platform/Windows)
endif()

This way, using Clang with MinGW will force GNU-style platform options
instead of VS-style Windows options.  Is this more or less the "right way"
to fix this in CMake?


On Wed, May 23, 2012 at 3:22 PM, Justin Holewinski <
justin.holewinski at gmail.com> wrote:

> 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
>
>


-- 

Thanks,

Justin Holewinski
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20120524/28f5a084/attachment.htm>


More information about the CMake mailing list