Eclipse MinGW undefined reference to SDL functions - c

So I've been searching for nigh on two hours now, haven't found a single working solution. I'm using SDL 2.0.4, and all the libraries are for the x64 architecture. I don't get the errors with SDL v1, but I need some of the newer functions. Here's what's coming up:
Info: Internal Builder is used for build
gcc -o Winchester.exe "src\\Winchester.o" -lmingw32 -lSDL2
src\Winchester.o: In function `SDL_main':
C:\Users\inigo\workspace\Winchester\Debug/../src/Winchester.c:17: undefined reference to `SDL_Init'
C:\Users\inigo\workspace\Winchester\Debug/../src/Winchester.c:20: undefined reference to `SDL_CreateWindow'
C:\Users\inigo\workspace\Winchester\Debug/../src/Winchester.c:22: undefined reference to `SDL_Quit'
C:\Users\inigo\workspace\Winchester\Debug/../src/Winchester.c:26: undefined reference to `SDL_CreateRenderer'
C:\Users\inigo\workspace\Winchester\Debug/../src/Winchester.c:28: undefined reference to `SDL_DestroyWindow'
C:\Users\inigo\workspace\Winchester\Debug/../src/Winchester.c:29: undefined reference to `SDL_Quit'
C:\Users\inigo\workspace\Winchester\Debug/../src/Winchester.c:36: undefined reference to `SDL_PollEvent'
C:\Users\inigo\workspace\Winchester\Debug/../src/Winchester.c:39: undefined reference to `SDL_DestroyRenderer'
C:\Users\inigo\workspace\Winchester\Debug/../src/Winchester.c:40: undefined reference to `SDL_DestroyWindow'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libmingw32.a(main.o):(.text.startup+0xa7): undefined reference to `WinMain#16'
collect2.exe: error: ld returned 1 exit status
Any help?

Related

ALSA Lib 1.1.2 Compilation error

I am trying to cross compile ALSA Lib application for linux-arm based processor. I am using eclipse to do the build for me. The build phase of the application is successful but I get errrors when the gcc linker tries to complete.
I get the following errors
Building target: sound
Invoking: Cross GCC Linker
arm-linux-gnueabihf-gcc -L/proc/asound -L/srv/nfs/rootfs/usr/lib -Wl,-rpath-link,/srv/nfs/rootfs/usr/lib -L/srv/nfs/rootfs/lib -Wl,-rpath-link,/srv/nfs/rootfs/lib -o "sound" ./play.o
./play.o: In function main':
/home/neonws/sound/Debug/../play.c:13: undefined reference tosnd_pcm_open'
makefile:29: recipe for target 'sound' failed
/home/neonws/sound/Debug/../play.c:14: undefined reference to snd_strerror'
/home/neonws/sound/Debug/../play.c:20: undefined reference tosnd_pcm_hw_params_malloc'
/home/neonws/sound/Debug/../play.c:21: undefined reference to snd_strerror'
/home/neonws/sound/Debug/../play.c:26: undefined reference tosnd_pcm_hw_params_any'
/home/neonws/sound/Debug/../play.c:27: undefined reference to snd_strerror'
/home/neonws/sound/Debug/../play.c:32: undefined reference tosnd_pcm_hw_params_set_access'
/home/neonws/sound/Debug/../play.c:33: undefined reference to snd_strerror'
/home/neonws/sound/Debug/../play.c:38: undefined reference tosnd_pcm_hw_params_set_format'
/home/neonws/sound/Debug/../play.c:39: undefined reference to snd_strerror'
/home/neonws/sound/Debug/../play.c:44: undefined reference tosnd_pcm_hw_params_set_rate_near'
/home/neonws/sound/Debug/../play.c:45: undefined reference to snd_strerror'
/home/neonws/sound/Debug/../play.c:50: undefined reference tosnd_pcm_hw_params_set_channels'
/home/neonws/sound/Debug/../play.c:51: undefined reference to snd_strerror'
/home/neonws/sound/Debug/../play.c:56: undefined reference tosnd_pcm_hw_params'
/home/neonws/sound/Debug/../play.c:57: undefined reference to snd_strerror'
/home/neonws/sound/Debug/../play.c:62: undefined reference tosnd_pcm_hw_params_free'
/home/neonws/sound/Debug/../play.c:64: undefined reference to snd_pcm_prepare'
/home/neonws/sound/Debug/../play.c:65: undefined reference tosnd_strerror'
/home/neonws/sound/Debug/../play.c:71: undefined reference to snd_pcm_writei'
/home/neonws/sound/Debug/../play.c:72: undefined reference tosnd_strerror'
/home/neonws/sound/Debug/../play.c:78: undefined reference to `snd_pcm_close'
collect2: error: ld returned 1 exit status
make: *** [sound] Error 1
11:15:58 Build Finished (took 75ms)
I am using the Sample Playback Program from ASLA-LIB api.
I am wondering what is causing the linker to fail?
You're missing an asound library linkage, add -lasound to your linking flags (see this question which tells where to do that properly in Eclipse). And probably remove -L/proc/asound, I don't think you have your libraries there.

Cplex library gcc compilation link error

gcc -I/opt/cplex-studio-125/cplex/include -lcplex -L/opt/cplex-studio-125/cplex/lib/x86-64_sles10_4.1/static_pic mipex1.c
I'm trying to compile an example from cplex. -I option is fine. The -L option seems to be corrupt, since it can't find the function names.
Where is the error? In the specifiec link there is a libcplex.a.
/tmp/ccf5sKky.o: In function `main':
mipex1.c:(.text+0x9f): undefined reference to `CPXopenCPLEX'
mipex1.c:(.text+0xee): undefined reference to `CPXgeterrorstring'
mipex1.c:(.text+0x125): undefined reference to `CPXsetintparam'
mipex1.c:(.text+0x222): undefined reference to `CPXcreateprob'
mipex1.c:(.text+0x2e1): undefined reference to `CPXcopylp'
mipex1.c:(.text+0x334): undefined reference to `CPXcopyctype'
mipex1.c:(.text+0x380): undefined reference to `CPXmipopt'
mipex1.c:(.text+0x3cc): undefined reference to `CPXgetstat'
mipex1.c:(.text+0x403): undefined reference to `CPXgetobjval'
mipex1.c:(.text+0x474): undefined reference to `CPXgetnumrows'
mipex1.c:(.text+0x490): undefined reference to `CPXgetnumcols'
mipex1.c:(.text+0x4be): undefined reference to `CPXgetx'
mipex1.c:(.text+0x51c): undefined reference to `CPXgetslack'
mipex1.c:(.text+0x5f9): undefined reference to `CPXwriteprob'
mipex1.c:(.text+0x64d): undefined reference to `CPXfreeprob'
mipex1.c:(.text+0x697): undefined reference to `CPXcloseCPLEX'
mipex1.c:(.text+0x6e3): undefined reference to `CPXgeterrorstring'
collect2: error: ld returned 1 exit status
The order of appearance of the library matters. Change your compilation statement to
gcc -I/opt/cplex-studio-125/cplex/include mipex1.c L/opt/cplex-studio-125/cplex/lib/x86-64_sles10_4.1/static_pic -lcplex
(Generic version)
gcc -I/<path> -L<path> <source.c> -l<lib>
to put the library after the source file, so that, linker will search the library for the function called from the source file.

"undefined reference" when trying to use lp_solve in C/C++ on Linux

I'm new to linear programming and C. I am trying to use the lp_solve library to solve a linear equation. The problem is I can't get the demo code to work.
As described in the documentation, I downloaded lp_solve_5.5_dev.gz to my Linux machine. I extracted the files into the same folder as my code and tried to compile:
~/Desktop/Code/CA$ cc -o demo demo.c
/tmp/ccpeN8ZV.o: In function `demo':
demo.c:(.text+0x31): undefined reference to `make_lp'
demo.c:(.text+0x62): undefined reference to `set_col_name'
demo.c:(.text+0x7d): undefined reference to `set_col_name'
demo.c:(.text+0xcf): undefined reference to `set_add_rowmode'
demo.c:(.text+0x150): undefined reference to `add_constraintex'
demo.c:(.text+0x1e6): undefined reference to `add_constraintex'
demo.c:(.text+0x274): undefined reference to `add_constraintex'
demo.c:(.text+0x29c): undefined reference to `set_add_rowmode'
demo.c:(.text+0x30b): undefined reference to `set_obj_fnex'
demo.c:(.text+0x327): undefined reference to `set_maxim'
demo.c:(.text+0x33b): undefined reference to `write_LP'
demo.c:(.text+0x34e): undefined reference to `set_verbose'
demo.c:(.text+0x359): undefined reference to `solve'
demo.c:(.text+0x383): undefined reference to `get_objective'
demo.c:(.text+0x3a6): undefined reference to `get_variables'
demo.c:(.text+0x3d2): undefined reference to `get_col_name'
demo.c:(.text+0x429): undefined reference to `delete_lp'
collect2: ld returned 1 exit status
When I add liblpsolve55.a to the command I get the following errors:
~/Desktop/Code/CA$ cc -o demo demo.c liblpsolve55.a
liblpsolve55.a(lp_lib.o): In function `scaled_floor':
lp_lib.c:(.text+0x6923): undefined reference to `floor'
liblpsolve55.a(lp_lib.o): In function `scaled_ceil':
lp_lib.c:(.text+0x6f03): undefined reference to `ceil'
liblpsolve55.a(lp_lib.o): In function `set_XLI':
lp_lib.c:(.text+0x7aa2): undefined reference to `dlclose'
lp_lib.c:(.text+0x7bb3): undefined reference to `dlopen'
lp_lib.c:(.text+0x7bd1): undefined reference to `dlsym'
lp_lib.c:(.text+0x7d8a): undefined reference to `dlsym'
lp_lib.c:(.text+0x7da6): undefined reference to `dlsym'
lp_lib.c:(.text+0x7dc2): undefined reference to `dlsym'
liblpsolve55.a(lp_lib.o): In function `set_BFP':
lp_lib.c:(.text+0x7eb4): undefined reference to `dlclose'
lp_lib.c:(.text+0x7fc3): undefined reference to `dlopen'
lp_lib.c:(.text+0x7fe1): undefined reference to `dlsym'
lp_lib.c:(.text+0x831a): undefined reference to `dlsym'
lp_lib.c:(.text+0x8336): undefined reference to `dlsym'
lp_lib.c:(.text+0x8352): undefined reference to `dlsym'
lp_lib.c:(.text+0x836e): undefined reference to `dlsym'
liblpsolve55.a(lp_lib.o):lp_lib.c:(.text+0x838a): more undefined references to `dlsym' follow
................
I understand that the lp_solve libraries are not loaded in my code. Can you please tell me how I can properly link the lp_solve libraries?
You're just missing some compiler flags to include the proper libraries. As danielko said, a quick google search on the missing libraries brings up some suggestions. E.g.
Linux c++ error: undefined reference to 'dlopen'
http://sourceforge.net/p/dev-cpp/discussion/48211/thread/3bd8b8a1
These suggest your compilation should be something more like:
cc -o demo demo.c -ldl -llpsolve55
and the lpsolve documentation suggests a command that includes the project directory such as:
cc -I/lp_solve_5.5 -I/lp_solve_5.5/bfp -I/lp_solve_5.5/bfp/bfp_etaPFI -I/lp_solve_5.5/colamd $src -o MyExe.exe -lm -ldl

Compiling libjpeg on Windows using cygwin?

Which is the best way to compile libjpeg on a Windows machine? Should I use Microsoft Visual Studio or can I use something else like Cygwin?
Note: when I use Cygwin and copy makefile.vc to Makefile, jconfig.vc to jconfig.h and run this sample code: http://www.cim.mcgill.ca/~junaed/code/libjpeg_sample.tar.gz
then the compiler produces the following errors:
$ gcc main.c
C:\cygwin\tmp\ccwChyeY.o:main.c:(.text+0x5a): undefined reference to `jpeg_std_error'
C:\cygwin\tmp\ccwChyeY.o:main.c:(.text+0x7e): undefined reference to `jpeg_CreateDecompress'
C:\cygwin\tmp\ccwChyeY.o:main.c:(.text+0x93): undefined reference to `jpeg_stdio_src'
C:\cygwin\tmp\ccwChyeY.o:main.c:(.text+0xa9): undefined reference to `jpeg_read_header'
C:\cygwin\tmp\ccwChyeY.o:main.c:(.text+0xb7): undefined reference to `jpeg_start_decompress'
C:\cygwin\tmp\ccwChyeY.o:main.c:(.text+0x11b): undefined reference to `jpeg_read_scanlines'
C:\cygwin\tmp\ccwChyeY.o:main.c:(.text+0x178): undefined reference to `jpeg_finish_decompress'
C:\cygwin\tmp\ccwChyeY.o:main.c:(.text+0x186): undefined reference to `jpeg_destroy_decompress'
C:\cygwin\tmp\ccwChyeY.o:main.c:(.text+0x1f6): undefined reference to `jpeg_std_error'
C:\cygwin\tmp\ccwChyeY.o:main.c:(.text+0x21a): undefined reference to `jpeg_CreateCompress'
C:\cygwin\tmp\ccwChyeY.o:main.c:(.text+0x22f): undefined reference to `jpeg_stdio_dest'
C:\cygwin\tmp\ccwChyeY.o:main.c:(.text+0x269): undefined reference to `jpeg_set_defaults'
C:\cygwin\tmp\ccwChyeY.o:main.c:(.text+0x27f): undefined reference to `jpeg_start_compress'
C:\cygwin\tmp\ccwChyeY.o:main.c:(.text+0x2c7): undefined reference to `jpeg_write_scanlines'
C:\cygwin\tmp\ccwChyeY.o:main.c:(.text+0x2e5): undefined reference to `jpeg_finish_compress'
C:\cygwin\tmp\ccwChyeY.o:main.c:(.text+0x2f3): undefined reference to `jpeg_destroy_compress'
collect2.exe: error: ld returned 1 exit status
Well, if you just want the .dll it is already compiled.
https://cygwin.com/cgi-bin2/package-grep.cgi?grep=libjpeg&arch=x86_64

Compilation error in GCC on Linux

I am trying to compile my code for GnuTLS, but on compiling it gives the following errors.
I have checked gnutls.h is present on my system in /usr/include/gnutls/.
What else can be the cause?
gcc -o tls.o tls.c
/tmp/ccfyZ1Bd.o: In function `main':
tls.c:(.text+0x1c): undefined reference to `gnutls_global_init'
tls.c:(.text+0x28): undefined reference to `gnutls_anon_allocate_client_credentials'
tls.c:(.text+0x3c): undefined reference to `gnutls_init'
tls.c:(.text+0x58): undefined reference to `gnutls_priority_set_direct'
tls.c:(.text+0x74): undefined reference to `gnutls_credentials_set'
tls.c:(.text+0x79): undefined reference to `tcp_connect'
tls.c:(.text+0x91): undefined reference to `gnutls_transport_set_ptr'
tls.c:(.text+0x9d): undefined reference to `gnutls_handshake'
tls.c:(.text+0xdc): undefined reference to `gnutls_perror'
tls.c:(.text+0x109): undefined reference to `gnutls_record_send'
tls.c:(.text+0x125): undefined reference to `gnutls_record_recv'
tls.c:(.text+0x154): undefined reference to `gnutls_strerror'
tls.c:(.text+0x1e6): undefined reference to `gnutls_bye'
tls.c:(.text+0x1f2): undefined reference to `tcp_close'
tls.c:(.text+0x1fe): undefined reference to `gnutls_deinit'
tls.c:(.text+0x20a): undefined reference to `gnutls_anon_free_client_credentials'
tls.c:(.text+0x20f): undefined reference to `gnutls_global_deinit'
collect2: ld returned 1 exit status
This is a linking error. You need to include some library with the -l flag. Taking a wild guess without knowing your setup, I would try -lgnutls

Resources