I've been dealing with this issue for a few weeks now. I know that I'm probably just missing a minor step that I'm not aware of. So, any insight would be highly appreciated.
I'm trying to add some external libraries and use them in my C++ project. But don't seem to be able to figure out how. I read all the posts on internet about adding an external library but I believe I'm missing something!
Let's say, I want to add a simple library like Eigen (a header-only library). I copy and pasted the folder containing all the files in a subfolder in my project. I called the subfolder ThirdPartyLibraries.
INCLUDE_DIRECTORIES("${MAINFOLDER}/ThirdPartyLibraries/eigen")
Is there anything else I need to do?
Now, let's say I want to add another library like XGBoost (which has both header and source files). How would it be different?
I did similar things for XGBoost. My code may build with no error but that's as long as I don't refer to any of the functions in the library (basically just adding the library to my project without using it). When I try to use any of the functions, I get errors about "unresolved external symbol"s which makes me think I'm missing something while adding the libraries.
I've not added any libraries to my C++ code. So, if you can keep the explanations simple, that'd be great!
So, I resolved this problem and thought I share the solution for anyone else who might come across this problem.
The adding Eigen library is pretty straightforward as it's only header files. You just copy and paste all the header files somewhere in your project's directory and use include directories. You should be fine after.
Regarding the XGBoost linking, they just added the cmake file for that project. So, what you need to do is to build that project in Visual Studio. After building, you get .lib, .dll, and .exe files. You should only need .lib file. Copy and paste them somewhere in your project's directory and link it to the main project like this:
TARGET_LINK_LIBRARIES(ProjectName libxgboost)
Then, you have to cope and paste the include directory (containing the header files) from the xgboost directory to somewhere in your project directory. Besides libxgboost, you have to include rabit and xgboost libraries too. So, just copy and paste them when you're copy and pasting libxgboost.lib and link them using 'target_link_directories'.
When you use to use any of the functions from the library, make sure to include the header files.
Hope this helps others who have a hard time getting it to work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With