Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 and (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/ -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/ -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 ( and header files (x.hh) with shared library objects ( Source files are compiled, header files are included, and shared libraries are linked. – Andrea Corbellini Sep 25 '13 at 16:49

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

Your Answer


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.