Link with SDL and OpenGL under Ubuntu - c

I want to write a simple SDL OpenGL app, Codeblocks is the IDE I use.
When I create a new OpenGL project, it compiles fine, but if I try to use a function from the SDL header, le wild "undefined reference error" occurs. The same goes for the other direction, if I create a new SDL project, I can use the SDL functions without problems but I get a "undefined reference error" for the OpenGL functions...
NOTES:
I Use Ubuntu 11.10
I have installed the SDL and the OpenGL packages

You need to add the correct library. Headers just give the compiler sort of a index. But you need to tell the linker which libraries to actually pull in. You should find the linker options at the build settings. You need the following libraries for SDL + OpenGL
libGL.so ( -lGL linker switch )
libSDL.so ( -lSDL linker switch)
You may also require libGLU.so if you're using glu… functions.

Asking pkg-config is the preferable thing for obtain the particular flags and options needed for compilation and linkage against SDL and Mesa's GL+GLU. (Some GL implemenetations may not be shipping .pc files, but they should still be used where available.)

Related

Where is freeglut.a in cygwin?

I'm trying to implement a little OpenGL renderer in VSCode with cygwin's gcc, using freeglut as windowing system and I'm failing linking against freeglut. I have no clue what the library is called, according to what I found on the web, I should be able to link with -lfreeglut, but this gives me a the following:
/usr/lib/gcc/x86_64-pc-cygwin/9.3.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lfreeglut
collect2: error: ld returned 1 exit status
I searched my cygwin folder for "glut" and found many things, but no library. Funny enough the headers are present. Btw, I installed the freeglut package (mingw64-x86_64-freeglut v 2.8.1-1) with cygwin's package installer. Also, I'm completely unexperienced in GNU systems, so the answer may be quite straightforward.
I think was never -lfreeglut but always -lglut
Try compiling with the normal GLUT library package
libglut-devel: OpenGL Utility Toolkit library
it includes the shared library
usr/lib/libglut.dll.a
both headers
usr/include/GL/freeglut.h
usr/include/GL/freeglut_ext.h
usr/include/GL/freeglut_std.h
usr/include/GL/freeglut_ucall.h
usr/include/GL/glut.h
In general you can use cygcheck for finding the needed package.
$ cygcheck -p libglut.dll.a
Found 5 matches for libglut.dll.a
libglut-devel-2.8.1-1 - libglut-devel: OpenGL Utility Toolkit librar
y (installed binaries and support files)
libglut-devel-3.0.0-1 - libglut-devel: OpenGL Utility Toolkit librar
y
libglut-devel-3.2.1-1 - libglut-devel: OpenGL Utility Toolkit librar
y
...

How to cross compile GSL library for arm-none-eabi-gcc?

I need to use the GSL library in my program on LPCXpresso 4367(ARM CORTEX M4). I tried to follow the library linking procedure for LPC xpresso but the MCU linker is giving me these errors:
MCUXpressoIDE_10.3.0_2200\workspace\test1\Debug/../src/test1.c:53: undefined reference to 'gsl_linalg_LU_decomp'
MCUXpressoIDE_10.3.0_2200\workspace\test1\Debug/../src/test1.c:56: undefined reference to 'gsl_matrix_alloc'
MCUXpressoIDE_10.3.0_2200\workspace\test1\Debug/../src/test1.c:57: undefined reference to 'gsl_linalg_LU_invert'
and so on for other functions as well.
I have the libgsl.a and libgslcblas.a precompiled libraries for windows which works perfectly on codeblocks on windows with GCC compiler.
I read that I need to crosscompile library for the arm-none-eabi-gcc toolchain. But can someone please provide me the procedure as well?
the libgsl.a and libgslcblas.a precompiled libraries for windows
Those won't do for ARM.
In order to work on another platform, these libs need to be compiled from source code with the proper compiler (and settings - Cortex-M4F requires Thumb2 instruction set).
As the libraries are precompiled for Windows they don't work for ARM (as it is said in the other answer)
You need to cross compile the libraries first. If you install the GSL libraries following this procedure, you only need to change the parameters in the ./config according to your platform, for example I used:
./config --host=arm-linux-gnueabihf --prefix=/home/yourname/gsl_arm
Inside the .zip file with the gsl-2.5 files, there is a file called INSTALL. There you can find more details on the options for cross compiling.
Make sure to make clean before if you have already compiled the library for different settings. After cross-compiling the library when you run make check on the terminal you will probably get errors, but still it works. Continue with make install and you are ready to use it.

arm-linux-gnueabi-gcc does not find library

I'm trying to compile a c program in the paparazzi autopilot environment with OpenGL ES support for an ARM Mali GPU. I've compiled the libGLESv2 libraries from the Mali SDK, and everything worked fine. Now I'm trying to get the cross-compiler to find such libraries, but it says:
/usr/lib/gcc-cross/arm-linux-gnueabi/5/../../../../arm-linux-gnueabi/bin/ld: cannot find -lGLESv2
I tried to add the -v option to check the library path and it says:
LIBRARY_PATH=/usr/lib/gcc-cross/arm-linux-gnueabi/5/:/usr/lib/gcc-cross/arm-linux-gnueabi/5/../../../../arm-linux-gnueabi/lib/../lib/:/lib/../lib/:/usr/lib/../lib/:/usr/lib/gcc-cross/arm-linux-gnueabi/5/../../../../arm-linux-gnueabi/lib/:/lib/:/usr/lib/
I've placed the libGLESv2.so library in the first of such directories but still it doesn't work. What do you suggest?
Thanks,
Davide
You can try the solution from here
add "link_directories(/home/davide/Scaricati/Mali_OpenGL_ES_SDK_v2.4.4/lib/arm)" in CMakeLists.txt

How can I use opencv in my cuda code?

I have installed opencv and Cuda.I have made some opencv code and now I wanna try to make it run faster using CUDA.The problem is that the opencv GPU module does not satisfy me. How can I make a CUDA code to include and use opencv libraries and functions exactly like my .cpp files?I include the needed .h files (cv.h highgui.h) that I moved to the "include" CUDA folder in my CUDA code but when I try to compile it using nvcc it says
Undefined symbols for architecture i386:
"_cvLoadImage", referenced from:
_main in tmpxft_000177b6_00000000-14_cuda.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
which means that it does not understand the functions so the libraries are not included the right way as far as I can see.How can I make it work?
As far as I know, you can't just include OpenCV functions direclty in CUDA code. CUDA has its own way of programming and code made for CPU can't run on GPU directly.
I would suggest you to look at the documentation to understand how works CUDA.
If the gpu build of OpenCV does not satisfy you maybe you should make your own implementation of those functions.
OR
you just want to use openCV on CPU and also use CUDA for some other computation ?
In the case, I think you have to create a cpp file which wraps your CUDA functions.
You will be able to use your wrapped functions as usual in your C or C++ code.
I think, the "Getting Started with GPU-accelerated Computer Vision using OpenCV and CUDA" webinar materials should help. You can find them here: link
You better not try to mix between opencv headers and nvcc compiler, this is a bad practice.
Opencv is built in library which was build using CMAKE (usually in windows under visual studio)
When you include an opencv header in nvcc compiler, you have to include all the "presents" you get from opencv, e.g: external dll, headers and extern function expected in opencv code.
What I find is the most appropriate solution in your case, would be to write a code which compiles in VS, refer to you CUDA code and Opencv's CUDA back and forth (you can always use primitives and extern functions).

Linking gfortran libraries to c++ program in CodeBlocks under Ubuntu

I have an Ubuntu under Vmware, and use Code::Blocks, as I am not a very powerful command line user
and prefer IDE to Vim+console.
I am trying to compile a program which uses a c++ wrapper to fortran library.
However compiling gives me the following errors:
undefined reference to `_gfortran_compare_string'
There are a lot of errors of this type and a bunch of other similar to this one.
I have gfortran 4.6.3. I found searching that it is probably a linking problem, and people say to
use -lgfortran option for linker. When I add this to linker options in the Code::Blocks it does not change anything, errors continue. So, here are some question:
Is this a correct option for linker?
May be I have to give linker a direct path to the fortran library?
How do I find where are the fortran libraries installed? (I don't know a lot about linux ((( )
What am I doing wrong and how to fix it.
Have you added gfortran as a library to linked to your project or lgfortran? The l is just an option for the g++ for linking the library gfortran to your code. I am not familar with Code::Blocks but you should look for a place where you can enter libraries you want to use and add the gfortran directly.
My guess is that the Code::Blocks side can help you to find this place.
Kim Kulling
My guess is something like /bin/lib /usr/lib or /usr/local/lib. Just take a look into your filesystem. Unfortunately I do not have a Linuix at work. Maybe someone else?
Kim Kulling

Resources