I want to set the linker correctly so an eclipse project can work properly.I have added the the folder that my header and cpp files exist to the c/c++ compiler directories. I have to set the linker also. I do n ot know how cause the linker in the tool settings wants to add a library (an .a file that does not exist cause none makes it), so since i do not have any .a file i get error at the functions cause i can give the folder path to the linker but inside there there is no .a file. What can i do.
Related
I would like to use Gurobi in a C++ project I have in Eclipse. I tried multiple manuals/tutorials (including THIS on how to do the same in Visual Studio) to add the hook up the Gurobi files with Eclipse/GCC, but I just couldn't make it work. I feel like I don't understand enough how these things should work in the first place.
In my Gurobi folder I have 3 folders, that in my opinion are important: include (with .h files), lib (with .lib files and NO .so or .a files) and src (with .cpp & .h files).
include: I added the path to this folder to C/C++ Build -> Settings -> GCC C++ Compiler -> Includes -> Include paths, I guess this is for the compiler to see the .h files. I also added it to C/C++ General -> Paths and Symbols -> Includes -> Include directories, I guess this is for the linker to see the .h files.
lib: I first added the folder path to C/C++ Build -> Settings -> MinGW C++ Linker -> Libraries -> Libraries (-l), however after searching online it seems to me this option only works for libraries with standard names and extensions. It also gave me the error ld.exe: cannot find -lc:/gurobi900/win64/lib/, so I deleted it and added the two .lib file paths separately to Miscellanous -> Other objects.
I got to the point where #include "gurobi_c++.h" works, however, already Eclipse underlines a line where I am defining a GRBEnv() object, that is declared in include/gurobi_c++.h, but defined in src/cpp/Env.cpp. Also if I try to compile, I get undefined reference errors. This means neither the Linker nor the Compiler can see the definition of GRBEnv().
Is there a way to tell the linker/compiler where the .cpp files are? Is it happening automatically, based on the path of the include folder? Am I supposed to link the .lib or the .cpp files?
I would greatly appreciate even if someone just pointed out mistakes in my understanding.
I would like to use Gurobi in a C++ project I have in Eclipse. I tried multiple manuals/tutorials (including THIS on how to do the same in Visual Studio) to add the hook up the Gurobi files with Eclipse/GCC, but I just couldn't make it work. I feel like I don't understand enough how these things should work in the first place.
In my Gurobi folder I have 3 folders, that in my opinion are important: include (with .h files), lib (with .lib files and NO .so or .a files) and src (with .cpp & .h files).
include: I added the path to this folder to C/C++ Build -> Settings -> GCC C++ Compiler -> Includes -> Include paths, I guess this is for the compiler to see the .h files. I also added it to C/C++ General -> Paths and Symbols -> Includes -> Include directories, I guess this is for the linker to see the .h files.
lib: I first added the folder path to C/C++ Build -> Settings -> MinGW C++ Linker -> Libraries -> Libraries (-l), however after searching online it seems to me this option only works for libraries with standard names and extensions. It also gave me the error ld.exe: cannot find -lc:/gurobi900/win64/lib/, so I deleted it and added the two .lib file paths separately to Miscellanous -> Other objects.
I got to the point where #include "gurobi_c++.h" works, however, already Eclipse underlines a line where I am defining a GRBEnv() object, that is declared in include/gurobi_c++.h, but defined in src/cpp/Env.cpp. Also if I try to compile, I get undefined reference errors. This means neither the Linker nor the Compiler can see the definition of GRBEnv().
Is there a way to tell the linker/compiler where the .cpp files are? Is it happening automatically, based on the path of the include folder? Am I supposed to link the .lib or the .cpp files?
I would greatly appreciate even if someone just pointed out mistakes in my understanding.
how can I add *.h file with it's own compiled *.o file to my project, so I can use it's functions etc. I'm using codeblocks and trying to set paths for compiler & linker but it still can't recognize the functions.
I take it that you have a .h file and .o file all ready from another project, and wish to add them to your current project, but want to keep the .o definitions hidden from the external users of your current project.
Add your .o file to your current project, and make sure it physically exist in your linker path. Then add the .h file to this project, and make sure it exists alongside your sources (not inside the include folder), and make sure it exists inside your compiler path.
Right-click the .o file and click on Properties. Then navigate to the Build tab, and check off 'Link file'.
Right-click your current project, and click on Build options. Then in the general build configuration, add -lNAMEOFOBJECTFILE.o to your linker options.
Now... this is not a typical pattern in C++ and I advise you look into creating a shared library that has the 'hidden' code you wish to use, and link your final binary against a .dll/.so. Also, if the .o file uses any external dependencies, then this will not work for you, so the suggested route I recommend, is building a shared library file, then linking against that. When you release your code, you can always omit include .h files that have symbols that you want to keep hidden in your final API.
Good luck!
I have a small library project that uses OpenGL (glfw and glew). Now, the project compiles fine, but when I create a new project and statically link the library project, VS starts to throw errors in the library project. Why is that?
More specifically, I get this error:
error C1083: Cannot open include file 'GL/glew.h': No such file or directory (file: trenums3d.h)
The project setup is like this: There's the library project 'Foo', which is compiled into a static library ('Foo.lib'). The application project 'Bar' links 'Foo' (I added the folder where Foo.lib resides to Bar's 'Additional Library Directories', as well as the source folder of 'Foo' to Bar's 'Additional Include Directories'). If I compile only the library project, everything works just fine, but compiling the whole solution give me the aforementioned error.
This isn't a proper answer to your question, but just an explanation of the steps required for building an application in a compiled language.
Building a project containing multiple files is a three-step process:
Creation and editing of source and header files
Compilation of the source files (this step contains many sub-steps). This step creates object files of all translation units
Linking of all object files and libraries to form the final executable
Error like the one shown in your question is emitted in the second step. Linking with libraries happens in a completely different step, and is usually done by a different program than the compiler.
To answer your question, if linking with a static library also requires linking with the other libraries that the static library depend on, then the answer is normally yes. Static libraries only contain the function in the actual libraries, you can look at a static library more as a collection or archive of object files. Static libraries does not contain any information about other libraries they depend on.
And as for your problem, with the pre-processor error, it's because you include a header file from your static library, and that header file in turn includes some header files. But the pre-processor doesn't have the secondary included header files in its default search path, so you need to add it.
This still have nothing to do with linking any library, this is a pure pre-processor issue, and is handled in step two in my list above.
I suspect the header files of your static library look like somewhat this:
#ifndef SOMECLASS_H
#define SOMECLASS_H
#include "GL/glew.h"
// ...
#endif
If you include this header file from another library or application, the compiler will open this file and will see that it needs to open GL/glew.h as well in order to be able to "understand" the definition of your class.
This means you need to supply at least the header files of glew. The only way to get rid of this is if you manage to only reference glew files from your .cpp files but not from your .h files. In some cases, forward declarations can be used, but not sure if this will work for glew.
Concerning the linker settings: In case your glew library is built statically as well, you may or may not have to supply that library file and link to it from your project. This depends on how you setup your linker for your own static library. If you have troubles in this step, create a new question.
I am working on a dataManagement project that periodically deletes files in a specific folder. The solution has three projects of which, one is the application and the other two are static libraries. Now I want to add one more project which is a static library used for logging. The logging static library project has a header file which the application project refers. When I build the solution, I am getting error as the header file is not found. When I added the logging static library project, I also made the application project dependent on it by checking the appropriate bix in the project dependencies.
Can anyone please help me?
It needs an additional include file path to reference the header file directory...
Project->Properties->Config Properties->C/C++->Additional Include Directories
it doesn't auto pick up the header file paths, it just knows how to link to the project.... Its completely undefined where the header file should be. or even if you have a header file, you can forward reference the thing in the other project if you like!
There are two things you need to do to get a statically linked library working in VS. The compiler needs to be able to find the declaration for the symbols that you're referencing and the linker needs to be able to resolve the full definition. When you add the .lib file to the VS project this meets the second obligation. To meet the first you must include the header somewhere in your source hierarchy before the first reference and you must also tell the project where to find the header files. The dependency settings in VS only set the build order - they will not help here. You need to make sure that the folder that your header files are in is added to the "Additional Include Directories" setting in the project properties, or is one of the global include directories in the main VS Options. You must also make sure that the .lib is added to the linker's "Additional Dependencies" setting.