1

I am trying to link some libraries my g++ code and I am getting the following error:

$ g++ -O myprob.o  -o myprob -Wl,-rpath $PATH/lib -L$PATH/lib -lprob7_cpp -lprob7
g++.exe: error: c:\mypath;c:\mypath\lib: Invalid argument

If I try and run this command without the -Wl,-rpath $PATH/lib part, which I think I should be able to do, then I get this error:

$ g++ -O myprob.o  -o myprob -L$PATH/lib -lprob7_cpp -lprob7
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lprob7_cpp
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lprob
collect2.exe: error: ld returned 1 exit status

I have been tinkering with this for hours and can't seem to figure this out.

I have already compiled my .cpp files successfully with the following command:

$ g++ -O -I$PATH/include -c myProb.cpp -o myProb.o

How can I correct these errors?

2
  • g++ failed to find library prob7_cpp and prob7, namely libprob7_cpp.a and libprob7.a files in library search path set by -L. Check your configuration and files you aleady built.
    – yaegashi
    Commented Aug 21, 2015 at 11:03
  • The $PATH is a variable in linux containing all paths to look for command binaries when calling them by name. You probably were trying to use the path to working directory $PWD?
    – danba
    Commented Nov 14, 2018 at 11:37

1 Answer 1

2

Do not use your $PATH variable in the compile line options !!!

Try to use this command line in place:

$ g++ -O myprob.o  -o myprob -Wl,-rpath ./lib -L./lib -lprob7_cpp -lprob7

You must log in to answer this question.

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