-1

I can't seem to get this working. I have a c++ script that i haven't written myself, that i need to compile with g++. The start of the script looks like this:

#include "x.hh"
#include "y.hh"

#include <iostream>
...

I understand that when using include with quotation marks, that means there are external libraries that have to be included when doing the compiling. The header files, x.hh and y.hh, as well as the files x.cc and y.cc (wich i guess are the libraries) plus the main script are all in the same folder. I've tried to compile them with:

g++ Documents/Cpp/script.cc -o script -L Documents/Cpp -lx -ly

This returns the error:

/usr/bin/ld cannot find -lx
/usr/bin/ld cannot find -ly
collect2 returned 1 exit status

The search path isn't the same as i specified. Even if I write:

g++ Documents/Cpp/script.cc -o script -L sdfsdf/sdfsd-lx -ly

It still looks in /usr/bin/ld folder. No matter what i write in -L, I cant get it to work. How?

1
  • I think you are confusing source files (x.cc) and header files (x.hh) with shared library objects (x.so). Source files are compiled, header files are included, and shared libraries are linked. Sep 25, 2013 at 16:49

1 Answer 1

0

You can use -I to specify an include directory.

So the "compile command" should be like this:

g++ -o output_name -I/include/path source.cpp

Using your source name and include path:

g++ -o script -I~/Documents/Cpp ~/Documents/Cpp/script.cc 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .