Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to find package and link library without cmake in simple cpp file?

file name: main.cpp

#include<iostream>
#include"boolector.h"

using namespace std;
int main()
{
Btor* btor=boolector_new();
cout<<"hello world";
boolector_delete(btor);
}

What if I don’t want to make CMake project, just a C++ file and still wants to link library as in CMake?

I want equivalent to following (in CmakeLists.txt) in g++.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

find_package(Boolector)
target_link_library(project_name Boolector::boolector)

Documentation can be found at Text.

/usr/local/bin/boolector 
/usr/local/include/boolector
/usr/local/include/boolector/boolector.h
/usr/local/include/boolector/btortypes.h
/usr/local/lib/libboolector.a
/usr/local/lib/libboolector.so

Result of locate boolector

/usr/local/lib/cmake/Boolector
/usr/local/lib/cmake/Boolector/BoolectorConfig.cmake
/usr/local/lib/cmake/Boolector/BoolectorConfigVersion.cmake
/usr/local/lib/cmake/Boolector/BoolectorTargets-release.cmake
/usr/local/lib/cmake/Boolector/BoolectorTargets.cmake

Result of locate Boolector

I am using CentOS.

>Solution :

You can use -l, -L and -I options of g++ like:

g++ -L /usr/local/lib/ -lboolector -I /usr/local/include/boolector main.cpp -o main
  • -l option is for setting the name of the library to be linked
  • -L option is for setting the path where the library to be linked has to be searched
  • -I option is for setting the path where header files of the library are present

To run the executable, you need to make sure that the libraries are there in the LD_LIBRARY_PATH environment variable.

export LD_LIBRARY_PATH=$LD_LIBARY_PATH:/usr/local/lib
./main
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading