Code::Blocks Forums
User forums => Using Code::Blocks => Topic started by: greenninja on January 24, 2010, 09:09:43 am
-
I am trying to add prewritten files which are already compiled to .o files. I have the header for it but can't seem to figure out how to add the .o file so the linker will recognize it. I have tried just adding it to the project where you add the source .c or .cpp etc files, and I've tried only including the header, but if I only include the header I don't know where to put the .o file. Any help would be appreciated. :)
Thanks
-
Right click on the object file in the in the "management -> projects" pane, then "Properties -> Build options".
There verify that the "link file" option is checked.
Look here http://wiki.codeblocks.org/index.php?title=FAQ#Q:_How_do_I_troubleshoot_an_compiler_problem.3F and post the output if you can't handle it yourself
p.s. I've tried it and it doesn't work, it might be bug in C::B.
-
You can try to add the object-file to the other linker options of your project, use the path relative to your projects base-path.
-
You can try to add the object-file to the other linker options of your project, use the path relative to your projects base-path.
I am wondering if you can be a little more specific? I have tried adding that .o file just about everywhere I can but for most of the places I have tried, it doesn't even show up. So I'm probably just not sure where specifically to look.
I feel like I have gone through all the linker settings that I could possibly find but just keep coming up empty-handed. When I have the .o file included with the link file option checked as oBFusCATed mentioned, I get the maximum number of errors for "undefined reference to ..."
When I only include the header and not the .o file I get the 3 undefined references to the 3 functions that would call a funtion in that .o file. Note this is when I have placed a second copy of the .o file in the root folder / obj/debug where the main.o file is placed. Without it there it doesn't work at all.
-
You can try to add the object-file to the other linker options of your project, use the path relative to your projects base-path.
I am wondering if you can be a little more specific? I have tried adding that .o file just about everywhere I can but for most of the places I have tried, it doesn't even show up. So I'm probably just not sure where specifically to look.
I feel like I have gone through all the linker settings that I could possibly find but just keep coming up empty-handed. When I have the .o file included with the link file option checked as oBFusCATed mentioned, I get the maximum number of errors for "undefined reference to ..."
When I only include the header and not the .o file I get the 3 undefined references to the 3 functions that would call a funtion in that .o file. Note this is when I have placed a second copy of the .o file in the root folder / obj/debug where the main.o file is placed. Without it there it doesn't work at all.
The header-file is needed in any cases.
Add the object-file to "Build options... -> Linker settings -> Other linker options:"
If you still get undefined references, it might be that the object-file does not include the needed functions, or you have an object-file build with a C-compiler and you use it from within a C++-project or vice versa, or it is build with another (possibly incompatible) compiler.
-
Use "nm" command line tool to find what symbols the object file has.
-
Use "nm" command line tool to find what symbols the object file has.
Hey - there is the "symbol table" plugin (a wrapper around nm) that does this more nicely and is integrated into C::B. ;-)
-
Well I added the .o file to the linker like Jens suggested, and it seems to be ok, the errors for it no longer assert, but I also have a .a file that needs to be included as well, so now I am trying to compile that into a .o file and include it as well. I have tried including it similarly to a .cpp or .c file and tell it to link / compile but all attempts i get at this result in an error log similar to this.
mingw32-gcc.exe -Wall -W -g -c "C:\Users\Joshua\Desktop\College\EECS 482\Proj 1 Threads\Threads\Sample Thread\libinterrupt.a" -o obj\Debug\libinterrupt.o
mingw32-gcc.exe: C:\Users\Joshua\Desktop\College\EECS 482\Proj 1 Threads\Threads\Sample Thread\libinterrupt.a: linker input file unused because linking not done
mingw32-g++.exe -o "bin\Debug\Sample Thread.exe" obj\Debug\main.o thread.o obj\Debug\libinterrupt.o
mingw32-g++.exe: obj\Debug\libinterrupt.o: No such file or directory
additionally for the project spec when running this on a linux remote terminal the command line to run this is:
g++ -m32 thread.o main.cc libinterrupt.a -ldl
When I run this with my files on a linux remote terminal it runs perfect, so the .a and .o files are complete, so I am the one messing this up lol. I have searched the internet for those compile flags and can't find anything. If anybody has any further suggestions for the .a file issues, I'd greatly appreciate the help. I thought it was working but apparently the .o file problems were asserting first so I didn't realize it was a problem.
Thanks in advance!
-
.a file is a static lib (an Ar archive with object files).
Add it in the linker option as any other lib.