SFML community forums

Bindings - other languages => C => Topic started by: migf1 on December 22, 2013, 02:53:28 am

Title: CSFML static linking & dlls
Post by: migf1 on December 22, 2013, 02:53:28 am
Hello everybody, my 1st post here (btw, big thanks for C/SFML).

I've just set up CSFML 2.1 to give it a go, on a vanilla mingw32 toolchain, with gcc 4.7.0 on Win XP SP3...

Code: [Select]
> gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/unix/mingw/bin/../libexec/gcc/mingw32/4.7.0/lto-wrapper.e
xe
Target: mingw32
Configured with: ../gcc-4.7.0/configure --enable-languages=c,c++,ada,fortran,obj
c,obj-c++ --disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgo
mp --disable-win32-registry --enable-libstdcxx-debug --disable-build-poststage1-
with-cxx --enable-version-specific-runtime-libs --build=mingw32 --prefix=/mingw
Thread model: win32
gcc version 4.7.0 (GCC)

No problems, all is fine with the sample code written with notepad++ and compiled via the command line.

But am I supposed to have CSFML's bin folder in the PATH environment variable, even when I'm linking statically? If I don't, the runtime complains it cannot find the CSFML dll's...

Code: [Select]
gcc -g3 -std=c99 -Wall -Wextra -DSFML_STATIC test.c -o test.exe -Ic:/unix/csfml/include -Lc:/unix/csfml/lib/gcc -lcsfml-graphics -lcsfml-audio -lcsfml-window -lcsfml-network -lcsfml-system -Wl,--subsystem,windows

I took a wild guess and also defined -DCSFML_STATIC... did no difference.

Thanks in advance.
Title: Re: CSFML static linking & dlls
Post by: Laurent on December 22, 2013, 08:25:37 am
There's no static version of CSFML.
Title: Re: CSFML static linking & dlls
Post by: Jebbs on December 22, 2013, 10:15:03 am
There's no static version of CSFML.

Shouldn't it be theoretically possible though? If you built a static version of csfml and sfml, and then linked all dependencies? Unless I am missing something, in which case I will feel very silly.
Title: Re: CSFML static linking & dlls
Post by: Laurent on December 22, 2013, 03:10:13 pm
Quote
Shouldn't it be theoretically possible though? If you built a static version of csfml and sfml, and then linked all dependencies? Unless I am missing something, in which case I will feel very silly.
You wouldn't be able to link a static version of CSFML, since it's written in C++. Your C linker would complain about all these crazy C++ symbols that it doesn't know about.

Sorry for making you feel silly ;D
Title: Re: CSFML static linking & dlls
Post by: migf1 on December 22, 2013, 04:25:07 pm
It makes perfect sense, thanks for the rapid responses guys!
Title: Re: CSFML static linking & dlls
Post by: Jebbs on December 22, 2013, 06:08:19 pm
Quote
Shouldn't it be theoretically possible though? If you built a static version of csfml and sfml, and then linked all dependencies? Unless I am missing something, in which case I will feel very silly.
You wouldn't be able to link a static version of CSFML, since it's written in C++. Your C linker would complain about all these crazy C++ symbols that it doesn't know about.

Sorry for making you feel silly ;D

That's ok. :P

I think my view on what will and won't link correctly is skewed because of D. I'm fairly certain that the D compiler would be ok with linking everything statically like how I described.
Title: Re: CSFML static linking & dlls
Post by: wintertime on December 23, 2013, 12:46:35 am
Maybe you could get it to work if you use a C++ linker with your C project?
Title: Re: CSFML static linking & dlls
Post by: Laurent on December 23, 2013, 08:16:58 am
Quote
Maybe you could get it to work if you use a C++ linker with your C project?
It would work, yes. In this case it would just be a C++ static lib linked to a C++ program.