User forums > Using Code::Blocks
How to link a .o file to a project
greenninja:
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
oBFusCATed:
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.
Jenna:
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.
greenninja:
--- Quote from: jens on January 24, 2010, 03:48:19 pm ---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.
--- End quote ---
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.
Jenna:
--- Quote from: greenninja on January 24, 2010, 04:23:17 pm ---
--- Quote from: jens on January 24, 2010, 03:48:19 pm ---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.
--- End quote ---
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.
--- End quote ---
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.
Navigation
[0] Message Index
[#] Next page
Go to full version