[CMake] Impossible to link SDLmain and LibXml2

Eric Noulard eric.noulard at gmail.com
Tue Mar 6 15:18:58 EST 2012


2012/3/6  <julien.plu at redaction-developpez.com>:
> Hi,
>
>
>
> I have a problem with cmake not to compile but to link my .exe.
>
>
>
> I use SDL, OpenGL, FMOD, LibXml2 and a personal library. But when I try to
> compile my program LibXml2 and SDLmain are not include into the command line
> to link my .exe.
>
>
>
> Enclosed my CMakeList.txt and CMakeCache.txt and here the line for the
> linker into build.make:
>
>
>
> Output/shootspace.exe: C:/MinGW/lib/libSDL.dll.a
>
> Output/shootspace.exe: C:/MinGW/lib/libfmodex.a
>
> Output/shootspace.exe: CMakeFiles/shootspace.dir/build.make
>
> Output/shootspace.exe: CMakeFiles/shootspace.dir/objects1.rsp
>
>                 @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR)
> --red --bold "Linking CXX executable Output/shootspace.exe"
>
>                 "/c/Program Files (x86)/CMake 2.8/bin/cmake.exe" -E remove
> -f CMakeFiles/shootspace.dir/objects.a
>
>                 /C/MinGW/bin/ar.exe cr CMakeFiles/shootspace.dir/objects.a
> @CMakeFiles/shootspace.dir/objects1.rsp
>
>                 /C/MinGW/bin/g++.exe      -Wl,--whole-archive
> CMakeFiles/shootspace.dir/objects.a -Wl,--no-whole-archive  -o
> Output/shootspace.exe -Wl,--out-implib,Output/libshootspace.dll.a
> -Wl,--major-image-version,0,--minor-image-version,0
> -Lsource/lib/gtl/lib/mingw -lmingw32 /C/MinGW/lib/libSDL.dll.a -lpthread
> -lglu32 -lopengl32 /C/MinGW/lib/libfmodex.a -lgtl -lkernel32 -luser32
> -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32
>
>
>
> As you can see, LibXml2 library and SDLmain library are found in
> CMakeCache.txt but not include in build.make because –lxml2 and –lSDLmain
> are missing.
>
>
>
> Why ? I do something wrong in my CMakeList.txt ?

yes.
since you did
Find_Package(LibXml2 REQUIRED)

you'll have to:

target_link_libraries(
    shootspace
    ${LIBXML2_LIBRARIES}

and not XML2_LIBRARY

in you CMakeCache.txt you'll see that SDLmain is not found.
//Path to a library.
SDLMAIN_LIBRARY:FILEPATH=SDLMAIN_LIBRARY-NOTFOUND

for SDL I suggest you read the documentation of the module:
cmake --help-module FindSDL
there are some explanation about SDLmain or not.

-- 
Erk
Le gouvernement représentatif n'est pas la démocratie --
http://www.le-message.org


More information about the CMake mailing list