mardi 31 octobre 2017

Compile a file including boost libraries and appropriate linker

I have the following main.cpp file.

#include <iostream>
#include <boost/asio.hpp>

int main() {
  return 0;
}

To test if my libraries are correctly installed, I'd like to compile it in its current state.

After having done a bit of research, I have found out that I need to:

  • Tell the compiler (g++) to lookup for appropriate headers with the following flag (here, i'm using boost library, installed through homebrew, hence the directory)
    • -L/usr/local/Cellar/boost/1.65.1/lib
    • -I/usr/local/Cellar/boost/1.65.1/inc
  • "Link" the library
    • -lboost_system

I am not sure to have fully understand the meaning of these flags, but I have the following compiling instruction

g++ main.cpp -o main -L/usr/local/Cellar/boost/1.65.1/lib -I/usr/local/Cellar/boost/1.65.1/include -lboost_system

And ... I have the following error message among warnings

Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

What am I doing wrong?

Didn't have this error when I was using a IDE such as XCode. I'm using the default Mac Terminal, with Atom as a code editor.

Thanks for your help,

Aucun commentaire:

Enregistrer un commentaire