1

When I execute this command

g++ -L/home/andrea/Desktop/cppTest/Test1/myLib -I/home/andrea/Desktop/cppTest/Test1/commons -lNames compiledObjects/SayHello.o -o SayHello

The compiler return this error:

/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: cannot find -lNames
collect2: error: ld returned 1 exit status

Why the compiler search "Names" here

/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld

instead of

/home/andrea/Desktop/cppTest/Test1/myLib

That is the path specified using -L argmunt?

Problem found

The real problem was that I've forgotten to name the library in this way libName.so

Community
  • 1
  • 1
Andrea Catania
  • 1,361
  • 3
  • 21
  • 37
  • Try to move -lNames to the last position in the command. And `/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld` is just a linker command which complains about not finding library – Severin Pappadeux Mar 03 '16 at 15:44

1 Answers1

3

The right syntax is as follows

g++ -I/home/andrea/Desktop/cppTest/Test1/commons  compiledObjects/SayHello.o -o SayHello -L/home/andrea/Desktop/cppTest/Test1/myLib -lNames

(i.e. -L and -l options at the end).

And ensure that the directory /home/andrea/Desktop/cppTest/Test1/ contains the library libNames.so.

Claudio
  • 10,614
  • 4
  • 31
  • 71
  • That is a stylistic choice. That does not alter the result. – R Sahu Mar 03 '16 at 15:47
  • It is *not*. gcc wants the linker options at the end of the command. Just play a bit with `CFLAGS`, `LDFLAGS` and `LDLIBS` to discover. See also http://stackoverflow.com/questions/45135/why-does-the-order-in-which-libraries-are-linked-sometimes-cause-errors-in-gcc – Claudio Mar 03 '16 at 15:48
  • I've tried but the problem is not the syntaxt but the library name – Andrea Catania Mar 03 '16 at 15:54