jmmut
jmmut

Reputation: 904

How to use conan's SDL2 in windows

I'm new to compiling with conan in windows and I'm struggling with using SDL2.

Here there's a hello world that uses conan, which compiles and runs fine in linux doing:

git clone https://bitbucket.org/mutcoll/conan-sdl2-hello-world.git
cd conan-sdl2-hello-world
conan install --build=missing
cmake -G "Unix Makefiles"
make
./bin/test_sdl2

but in windows (using git for windows bash, don't know if that's important) the link against SDL2 fails with errors like this:

testspriteminimal.obj : error LNK2019: unresolved external symbol _SDL_GetError referenced in function "int __cdecl LoadSprite(char *,struct SDL_Renderer *)" (?LoadSprite@@YAHPADPAUSDL_Renderer@@@Z) [C:\Users\josemi\Documents\conan\conan-sdl2-hello-world\test_sdl2.vcxproj]

the question is: How can I get a successful linking? preferably with shared (SDL2.dll). Thanks to everybody in advance, below there are some details, if anyone needs more details, just ask (for example, putting the whole compilation in pastebin).

Reproducing the error

This is my CMakeLists.txt

project(SDL2_test)
cmake_minimum_required(VERSION 2.8)

include(conanbuildinfo.cmake)
conan_basic_setup()


set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")    
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") # I think I should do this only if gcc

add_executable(test_sdl2 testspriteminimal.cpp)
target_link_libraries(test_sdl2 ${CONAN_LIBS})

and my conanfile.txt:

[requires]
SDL2/2.0.3@lasote/stable

[generators]
cmake

these are my settings my .conan/conan.conf (the ones that conan install is using):

[settings_defaults]
arch=x86_64
build_type=Release
compiler=Visual Studio
compiler.runtime=MD
compiler.version=14
os=Windows

I'm using these lines after cloning:

conan install --build=missing  # this works fine, compiles SDL2.dll, SDL2.lib, SDL2main.lib
cmake -G "Visual Studio 14"
cmake --build .    # this fails

that last command fails doing this (even though I can see that it is using the SDL2.lib):

Link:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\link.exe /ERRORREPORT:QUEUE /OUT:"C:\Users\josemi\Documents\conan\conan-sdl2-hello-world\bin\test_sdl2.exe" /INCREMENTAL /NOLOGO /LIBPATH:C:/Users/josemi/.conan/data/SDL2/2.0.3/lasote/stable/package/c85f9b402dd4d46acdf074e1c63b768a41181d7a/lib /LIBPATH:C:/Users/josemi/.conan/data/SDL2/2.0.3/lasote/stable/package/c85f9b402dd4d46acdf074e1c63b768a41181d7a/lib/Debug kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib SDL2.lib SDL2main.lib user32.lib gdi32.lib winmm.lib imm32.lib ole32.lib oleaut32.lib version.lib uuid.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"C:/Users/josemi/Documents/conan/conan-sdl2-hello-world/bin/test_sdl2.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:/Users/josemi/Documents/conan/conan-sdl2-hello-world/lib/test_sdl2.lib" /MACHINE:X86 /SAFESEH  /machine:X86 test_sdl2.dir\Debug\testspriteminimal.obj

some more warnings, maybe unrelated

sdl2 built for x86?

"C:\Users\josemi\Documents\conan\conan-sdl2-hello-world\ALL_BUILD.vcxproj" (destino predeterminado) (1) ->
"C:\Users\josemi\Documents\conan\conan-sdl2-hello-world\test_sdl2.vcxproj" (destino predeterminado) (3) ->

(Link destino) ->
C:/Users/josemi/.conan/data/SDL2/2.0.3/lasote/stable/package/c85f9b402dd4d46acdf074e1c63b768a41181d7a/lib\SDL2.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'X86' [C:\Users\josemi\Documents\conan\conan-sdl2-hello-world\test_sdl2.vcxproj]
C:/Users/josemi/.conan/data/SDL2/2.0.3/lasote/stable/package/c85f9b402dd4d46acdf074e1c63b768a41181d7a/lib\SDL2main.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'X86' [C:\Users\josemi\Documents\conan\conan-sdl2-hello-world\test_sdl2.vcxproj]

like ~200 warnings like the next one, with C functions:

C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\stdlib.h(354): warning C4514: 'abs': unreferenced inline function has been removed [C:\Users\josemi\Documents\conan\conan-sdl2-hello-world\test_sdl2.vcxproj]

Upvotes: 0

Views: 1870

Answers (1)

jmmut
jmmut

Reputation: 904

OK, answering my own question, the problem, as IInspectable pointed out, is that I was building my executable in 32 bits, and linking with a 64 bits SDL2. The way to tell conan to do the executable with 64 bits is:

cmake -G "Visual Studio 14 Win64"

instead of just cmake -G "Visual Studio 14" as I was doing before.

example: http://docs.conan.io/en/latest/getting_started.html#building-the-timer-example

Upvotes: 1

Related Questions