User forums > Using Code::Blocks
Can't link object file from another project
Aleksandr:
--- Quote from: scarphin on June 15, 2014, 04:36:36 pm ---If you are trying to add a library file or such, you should use the linker settings to accomplish that.
--- End quote ---
I am not trying, C::B allows me to do it. And yes, I know it and now I'm using this method.
--- Quote from: scarphin on June 15, 2014, 04:36:36 pm ---Or else AGAIN what is your intention in trying to add an '.o' file to a project?
--- End quote ---
Well, I'll try to explain it clearly.
First, in the Project build options→Linker settings file list is titled Link libraries. From this it is not clear (at least to me) that here you can also add the object files or compiled windows resource files.
Secondly, in the Properties→Build for each file, you can uncheck the Compile file leaving checked only Link file.
Hence, I concluded that the project may contain files that do not require compiling, but used when linking. I do not know how it is for you, but for me it is primarily the files .o, .a and .res.
Thirdly, about why I add the .o file to the project. It is smaller than the entire lib. It does not require compiling when building the project.
And finally, what would you advise if I have added to the project .res file, and not an .o file? Since when it is added to the project, the symptoms are the same.
oBFusCATed:
--- Quote from: eMan.Lived on June 15, 2014, 06:28:40 pm ---And finally, what would you advise if I have added to the project .res file, and not an .o file? Since when it is added to the project, the symptoms are the same.
--- End quote ---
RES files should work fine. If they don't please post a build log, exact steps to reproduce or even an example project.
About the object file: Probably it is a bug, but you'll have to wait for someone familiar with the build system to answer.
@Morten can you confirm this is bug, expected behaviour or something that a user should not do?
BTW: There are two workarounds:
1. Paste the relative path in the linker options
2. Use a static library. I don't know why do you think it is bigger in size, but it is not or at least in is not by much. A static library is just an ar archive containing object files and an index.
MortenMacFly:
--- Quote from: oBFusCATed on June 17, 2014, 02:05:00 am ---About the object file: Probably it is a bug, but you'll have to wait for someone familiar with the build system to answer.
@Morten can you confirm this is bug, expected behaviour or something that a user should not do?
--- End quote ---
Yes, its a bug. What <you can do as another workaround is to put it to the additional linker options.
However, I agree with oBFusCATed that using a static library for such purposes is way more convenient.
Aleksandr:
--- Quote from: oBFusCATed on June 17, 2014, 02:05:00 am ---RES files should work fine. If they don't please post a build log, exact steps to reproduce or even an example project.
--- End quote ---
Like in the first post, I created the empty project a. In the project Properties→Build targets→Type I selected GUI application. Added main.cpp file:
--- Code: (main.cpp) ---#include <windows.h>
int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow)
{
return 0;
}
--- End code ---
In the project folder I created a subfolder res\. Copied the resource.res there (you can create and build the project "Win32 GUI project" to get this one). Added this file to the project. Tried to build the project:
--- Code: ("Build log") ---i686-w64-mingw32-g++.exe -Wall -O2 -IC:\MinGW\include -c C:\Users\Aleksandr\Code\C++\a\main.cpp -o release\obj\main.o
i686-w64-mingw32-g++.exe -LC:\MinGW\lib -o release\a.exe release\obj\main.o release\obj\res\resource.res -static -s -mwindows
i686-w64-mingw32-g++.exe: error: release\obj\res\resource.res: No such file or directory
Process terminated with status 1 (0 minute(s), 4 second(s))
1 error(s), 0 warning(s) (0 minute(s), 4 second(s))
--- End code ---
As you can see the same problem.
--- Quote from: oBFusCATed on June 17, 2014, 02:05:00 am ---2. Use a static library. I don't know why do you think it is bigger in size, but it is not or at least in is not by much. A static library is just an ar archive containing object files and an index.
--- End quote ---
Maybe it's the fact that I was not entirely clear how the linking static libraries.
Now, I believe that in the resulting file will have all of the code is included in the library, ie all "archived" objects. Even those that are not used or needed. Correct me if I'm wrong.
oBFusCATed:
--- Quote from: eMan.Lived on June 17, 2014, 06:43:51 pm ---Correct me if I'm wrong.
--- End quote ---
You're wrong 50%. I'm not sure what is the default behaviour, but linkers can remove unused functions and code these days.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version