Can't compile a file with SDL library linked on Ubuntu - c

We have an assignment to compile a file with SDL library linked. The file itself shouldn't contain any errors since almost everyone managed to compile it. I've installed SDL 1.2 on Ubuntu 12.04 with the following commands:
sudo apt-get install libsdl1.2-dev
sudo apt-get install libsdl-image1.2-dev
sudo apt-get install libsdl-mixer1.2-dev
sudo apt-get install libsdl-ttf2.0-dev
I'm compiling it with the following command:
gcc -o sdl_introduction sdl_introduction.c `sdl-config --cflags --libs`
I'm using with gcc 4.6.3
and I'm getting this error:
/usr/local/lib/libSDL.so: undefined reference to `_XGetRequest'
collect2: ld returned 1 exit status
What could cause the problem?

I have faced the same problem as you, it is caused by the SDL library needing other libraries to link with on ubuntu(or linux generally)
I recommend copiling it with :
gcc -o sdl_introduction sdl_introduction.c -lX11 -pthread `sdl-config --cflags --libs`
Notice the added -lX11 and -pthread.
EDIT:
My bad I forgot that you must add -lX11 and -pthread after the other flags.
Resulting in:
gcc -o sdl_introduction sdl_introduction.c `sdl-config --cflags --libs` -lX11 -pthread

Related

Raspbian: arm-none-eabi-ld: cannot find -lm

I'm building an app on Raspebian (Rpi3b+) using the gcc-arm-none-eabi toolchain (which I installed via sudo apt-get install gcc-arm-none-eabi).
I successfully compiled my sources, but the linking step:
arm-none-eabi-ld modes.c.o turing.c.o light.c.o dark.c.o pix.c.o --relocatable -o tlrcextractortest -lm
fails with:
arm-none-eabi-ld: cannot find -lm
What could be wrong? Which package do I need to install to get the missing lib?

windows crosscompiling from linux entry point not found curl_easy_cleanup could not located

I am unsure of what could be causing this as I have tried recompiling libcurl and using pre-compiled binaries.
My compiler command
x86_64-w64-mingw32-gcc -Wall -Lwin-lib -Iwin-lib -I./ -D WIN32 -D CURL_STATICLIB -mwindows ... -o win-export/SLM.exe -lm -lraylib -ltmx -lxml2 -lzlibstatic -lcurl
There aren't any compiler errors or linker errors. Is this a problem with my compiler? Or one the other libraries I am using?

ld cannot find libjasper library

I am trying to link an application with gc on Ubuntu 18.04. ld cannot find the libjasper library. I installed it manually with these commands:
sudo apt update
sudo apt install libjasper1 libjasper-dev
but got this error:
/usr/bin/ld: cannot find -llibjasper
I tried this command to add the library but didn't work:
gcc -o cnn connected_layer.c connected_layer.h convolutional_layer.c convolutional_layer.h image.c image.h maxpool_layer.c maxpool_layer.h network.c network.h tests.c -Wall `pkg-config --cflags --libs opencv` -flto -ffast-math -L /usr/lib/x86_64-linux-gnu -l libjasper
Replace
-l libjasper
by
-l jasper
lib is just a mandatory suffix to library files, which is ignored when specifying the name to the linker.

gcc cannot find -lglfw3 && i was unable to add the path

I am running CentOS 6.4, I have just installed GLFW 3.0.4 for some software package for CFD L-B visualisation. That's not my issue, the issue is that I was following instructions to test of GLFW was installed properly, I ran into some issues.
I began by
g++ -c main.cpp
Which has outputted main.o file, and went onto run this with the help of advice of another thread :
g++ main.o -o main.exec `pkg-config --libs glfw3` -lGL -lGLU -lglfw3 -lX11 -lXxf86vm -lXrandr -lpthread -lXi -ldlD
which has then given me this error code:
Package glfw3 was not found in the pkg-config search path.
Perhaps you should add the directory containing `glfw3.pc'
to the PKG_CONFIG_PATH environment variable
No package 'glfw3' found
/usr/bin/ld: cannot find -lglfw3
collect2: ld returned 1 exit status
Have tried adding -L or -B to the path of glfw3.pc and no use,
Can you please advise on how I can get this to work properly?

centos: linking lib that doesn't have a .pc file for pkg-config

I'm trying to compile svg2pdf on centos. I think I've managed to get the required dependencies installed using yum:
sudo yum install librsvg2
sudo yum install cairo
The Makefile contains:
MYCFLAGS=`pkg-config --cflags librsvg-2.0 cairo-pdf` -Wall -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -
Wnested-externs -fno-strict-aliasing
MYLDFLAGS=`pkg-config --libs librsvg-2.0 cairo-pdf`
After typing 'make', the first couple of lines of output are:
cc `pkg-config --cflags librsvg-2.0 cairo-pdf` -Wall -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -fno-strict-aliasing `pkg-config --libs librsvg-2.0 cairo-pdf` svg2pdf.c -o svg2pdf
Package librsvg-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `librsvg-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'librsvg-2.0' found
There is no librsvg-2.0.pc on this system (but there is when I installed this using macports on my macbookpro).
How should I get this package linked? Should I change the Makefile, and if so, to what? Should I generate the .pc files, and if so, how? Or is there another way to resolve this?
Or, has anyone been successful at installing svg2pdf on centos, and, if so, how did you manage it?
I don't have much experience on linux, so I might be missing something obvious.
I think CentOS uses -devel packages. Have you installed librsvg2-devel and cairo-devel?

Resources