Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question
    
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. –  Andrea Corbellini Sep 25 '13 at 16:49

1 Answer 1

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 
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.