user14685345
user14685345

Reputation:

How to link libraries with g++ compiler?

I'm trying to link a game library for my game project in C++. I am using the g++ compiler and Atom Code Editor. Also on a Windows machine.

To link the library it needs to link those things:

The main.cpp file is at ProjectRoot/src/main.cpp and the library is at ProjectRoot/deps/lib_name Inside the library there is and include folder, with the .h file for including, and a lib folder, with the .lib file. It's a static linking library.

So far, I've tried the following commands:

g++ -o ExecutableName.exe -I /deps/lib_name/include -L /deps/lib_name/lib src/main.cpp

Well, that didn't work though... It said that there was no such file or directory as library_name.h...

I need to know if I'm doing anything wrong and also how to specify the additional dependencies.

Upvotes: 2

Views: 4902

Answers (1)

Prabhat Maurya
Prabhat Maurya

Reputation: 131

Every thing is correct . You just forgot to link the libraries . Do it as follows -

g++ -o ExecutableName.exe -I /deps/lib_name/include -L /deps/lib_name/lib src/main -l[library name] -l[library name]

Upvotes: 2

Related Questions