This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Link Errors
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Thomas Dineen <tdineen at ix dot netcom dot com>
- Cc: gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Fri, 31 Jul 2015 10:04:16 +0100
- Subject: Re: Link Errors
- Authentication-results: sourceware.org; auth=none
- References: <55BB2950 dot 3070408 at ix dot netcom dot com>
On 31 July 2015 at 08:52, Thomas Dineen wrote:
> Gentle People:
>
> I am getting the following link errors on these fairly trivial programs.
> Please note the the code compiles and links perfectly on Solaris with gcc
> with no linking command line options.
>
> Am I missing a -l library command line option?
>
> I will post the source on request.
>
> In what libraries are the symbols sprintf_s and WinMain@16 found?
> So exactly what do I add to the command line?
>
> These errors seem quite strange to me in that usually google will tell
> you
> what library the symbol is in and then you just add -llib to the command
> line?
>
> Please help I have spent hours on google have ended up exhausted and
> confused!
> Written at 12:51 AM!
>
> i686-pc-mingw32-gcc Test_Shared.c dlfcn.c -lpsapi -o Test_Shared.exe
>
> /tmp/ccJEa2nO.o:dlfcn.c:(.text+0x2fb): undefined reference to `sprintf_s'
> and WinMain@16
> collect2: error: ld returned 1 exit status
sprintf_s should be provided by the mingw runtime, I don't know about
WinMain@16 (have you written a main() function?)
I suggest you ask somewhere focusesd on mingw, because finding the
right libraries to link to is not really a GCC problem.
> i686-pc-mingw32-gcc dlfcn.c -lpsapi -o dlfcn.o
>
> /tmp/cc6fCJ7Q.o:dlfcn.c:(.text+0x2fb): undefined reference to `sprintf_s'
> /home/tdineen/Mxe_Cross_Environment_120213/mxe/usr/lib/gcc/i686-pc-mingw32/4.8.1/../../../../i686-pc-mingw32/lib/libmingw32.a(main.o):main.c:(.text.startup+0xa7):
> undefined reference to `WinMain@16'
> collect2: error: ld returned 1 exit status
> Linux3%
If you're trying to compile (not link a complete executable) to
produce a .o file you need to use -c
> i686-pc-mingw32-gcc Test_Lib.c -o Test_Lib.so
>
> /home/tdineen/Mxe_Cross_Environment_120213/mxe/usr/lib/gcc/i686-pc-mingw32/4.8.1/../../../../i686-pc-mingw32/lib/libmingw32.a(main.o):main.c:(.text.startup+0xa7):
> undefined reference to `WinMain@16'
> collect2: error: ld returned 1 exit status
If you're trying to create a shared library (not link a complete
executable) you need to use -shared