User forums > Using Code::Blocks

[HELP] How do I properly add a library to my project?

(1/2) > >>

zeruel_angel:
Hi everyone! this is my first time in this forum! =D

I have this little minor problem... I don't know how to add a library to my C::B project.

Im using C::B in win xp sp3

I Have an OpenGL+Glut project (I managed to create it using the project wizard) and everithing runs smooth... :)

Now I am in a need of some extra functionality for my project, so I googled a while and I found a mention of this library "mkOpenGLJPEGImage":
http://pheatt.emporia.edu/courses/2003/cs410s03/hand02/hand02.htm

The home page of that library is non existing nowadays.

This is a quote from the help file that came with the library:

--- Quote ---Adding the class to your MSVC++ project
To use the mkOpenGLJPEGImage class in your software, you need to do the following.

Copy the mkOpenGLJPEGImage.h header file into the source code directory or some into a directory in the "Include Files Path".
Add the mkOpenGLJPEGImage.h header file to your project as a source code file. This is not necessary but it allows MSVC to pop up completion boxes for the class which is always helpful.
Copy the mkOpenGLJPEGImage.lib library into either a directory in the "Library Files Path" or into the source code directory itself.
Add the mkOpenGLJpegImage.lib library to the project's "Object/Library Modules" under Project>Settings>Link>General
Now you're ready to compile your programs using the class.

--- End quote ---

I tried to add the libraries, I added the ".h" to my project, then added the ".dll" to the folder where the exe is compiled. Finally I went to "Project->Build Options->Linker settings" and added the path to the .lib file.

I compile and everithing goes OK till it gets to the linker time when I get this message:
"ld.exe cannot find -lmkOpenGLJPEGImage.lib"

By the way, the files for the library are:

--- Quote ---mkOpenGLJPEGImage.h
mkOpenGLJPEGImage.dll
mkOpenGLJPEGImage.lib

--- End quote ---

Can anyone point me in the right direction here? Because I searched all over the web and I can not get it to work, I dont know why.

I also read in another topic that if you put the library on the left side, It will get te prefix "-l" so I also tried adding "l" and "-l" to the ".lib" file and nothing.
I also added it on the right side like this: "-mkOpenGLJPEGImage.lib" and I told the compiler to search in the folder where the .lib file was. But that time I got compiler errors, the same I get if I remove the .lib file from the left side of the linker settings.

Thanks for reading my post!

See you later!

ollydbg:
What is your compiler error? Please post it here.
It seems it is a linker error.

Project build option-> Linker settings

You can either add c:\XXX\XXXX\ABC.lib in the left edit window.
Also you can try add -lABC  in the right edit window.

zeruel_angel:
FIRST OF ALL! thanks for the reply!

This is what I get if I don't add the .lib file anywhere:

--- Quote ----------------- Build: Release in glutProyect ---------------

[ 50.0%] mingw32-g++.exe -fexpensive-optimizations -Os -O3 -O2 -O1 -O   -fexpensive-optimizations -Os -O3 -O2 -O1 -O    -I"C:\<BLAH BLAH>\DevPak\include" -Ilib -I"C:\<BLAH BLAH>\DevPak\include" -I"C:\<BLAH BLAH>\glutProyect" -I"C:\<BLAH BLAH>\glutProyect" -c "C:\<BLAH BLAH>\glutProyect\main.cpp" -o obj\main.o
[100.0%] mingw32-g++.exe -L"C:\<BLAH BLAH>\DevPak\lib" -Llib -L"C:\<BLAH BLAH>\DevPak\lib"  -o glutProyect.exe obj\main.o   -s -s  -lglut32 -lopengl32 -lglu32 -lwinmm -lgdi32  -mwindows
obj\main.o(.text+0x113):main.cpp: undefined reference to `_imp___ZN17mkOpenGLJPEGImageC1Ev'
obj\main.o(.text+0x135):main.cpp: undefined reference to `_imp___ZN17mkOpenGLJPEGImage12SetDebugModeEb'
obj\main.o(.text+0x162):main.cpp: undefined reference to `_imp___ZN17mkOpenGLJPEGImage20GetOpenGLScreenImageEii'
obj\main.o(.text+0x181):main.cpp: undefined reference to `_imp___ZN17mkOpenGLJPEGImage10SaveToFileEPci'
obj\main.o(.text+0x1a0):main.cpp: undefined reference to `_imp___ZN17mkOpenGLJPEGImageD1Ev'
obj\main.o(.text+0x1d2):main.cpp: undefined reference to `_imp___ZN17mkOpenGLJPEGImageD1Ev'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
6 errors, 0 warnings

--- End quote ---
(I edited some parts of the PATHS to "<BLAH BLAH>" )

If I add it on the left panel in "linker settings" I get this:

--- Quote ----------------- Build: Release in glutProyect ---------------

[ 50.0%] mingw32-g++.exe -fexpensive-optimizations -Os -O3 -O2 -O1 -O   -fexpensive-optimizations -Os -O3 -O2 -O1 -O    -I"C:\<BLAH BLAH>\DevPak\include" -Ilib -I"C:\<BLAH BLAH>\DevPak\include" -I"C:\<BLAH BLAH>\glutProyect" -I"C:\<BLAH BLAH>\glutProyect" -c "C:\<BLAH BLAH>\glutProyect\main.cpp" -o obj\main.o
[100.0%] mingw32-g++.exe -L"C:\<BLAH BLAH>\DevPak\lib" -Llib -L"C:\<BLAH BLAH>\DevPak\lib"  -o glutProyect.exe obj\main.o   -s -s  -lmkOpenGLJPEGImage.lib -lglut32 -lopengl32 -lglu32 -lwinmm -lgdi32  -mwindows
C:\Dev-Cpp\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\mingw32\bin\ld.exe: cannot find -lmkOpenGLJPEGImage.lib
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
1 errors, 0 warnings

--- End quote ---
+

--- Quote ---ld.exe||cannot find -lmkOpenGLJPEGImage.lib|
||=== Build finished: 1 errors, 0 warnings ===|

--- End quote ---
BUT ONLY IF I ADD THE .LIB AND IT IS IN THE "ROOT" OF MY PROJECT. IF I ADD THE SAME .LIB BUT FROM ANOTHER FOLDER I GET THE SAME ERRORS THAT BEFORE.

If I add it in the left side, only works (trow the "cannot find") If I put "-lmkOpenGLJPEGImage" with ".lib" else, it says the same things that says if I dont put any lib anywhere.

Again, thanks!

See you later!

ollydbg:
Did you try add the library with full absolute path. I give you a screen shot of my OpenCV and GLUT project.
See below:


[attachment deleted by admin]

zeruel_angel:
Thanks again! I tried it but again, no luck... It must be a problem with the library, I will try another one, like Devil or GraphicsMagick, I hope I have more luck :P

Thank you very much!

Anyway, I attach a "blank" glut project with the library. (Just remember to change the linker settigns because I'm using absolute path) It will be awesome if you can give it a shoot.

Thanks!

See you later!

[attachment deleted by admin]

Navigation

[0] Message Index

[#] Next page

Go to full version