I'm compiling some cpp files with:
$ g -c --std=c 17 -I/antlr4/runtime/Cpp/runtime/src/ *.cpp
And everything goes fine:
$ ls -l *.cpp *.o
-rw-r--r-- 1 root root 76637 Dec 1 14:33 Java8Lexer.cpp
-rw-r--r-- 1 root root 370768 Dec 1 15:13 Java8Lexer.o
-rw-r--r-- 1 root root 925012 Dec 1 14:33 Java8Parser.cpp
-rw-r--r-- 1 root root 5037896 Dec 1 15:13 Java8Parser.o
-rw-r--r-- 1 root root 113 Dec 1 14:33 Java8ParserBaseListener.cpp
-rw-r--r-- 1 root root 2312 Dec 1 15:13 Java8ParserBaseListener.o
-rw-r--r-- 1 root root 109 Dec 1 14:33 Java8ParserListener.cpp
-rw-r--r-- 1 root root 2304 Dec 1 15:13 Java8ParserListener.o
-rw-r--r-- 1 root root 724 Dec 1 14:36 main.cpp
-rw-r--r-- 1 root root 324360 Dec 1 15:13 main.o
When I try to link with a library, it fails:
$ g *.o -l/antlr4/runtime/Cpp/dist/libantlr4-runtime.so.4.9.3
/usr/bin/ld: cannot find -l/antlr4/runtime/Cpp/dist/libantlr4-runtime.so.4.9.3
collect2: error: ld returned 1 exit status
This is weird because the shared library does exist:
$ ls -l /antlr4/runtime/Cpp/dist/libantlr4-runtime.so.4.9.3
-rwxr-xr-x 1 root root 1599624 Dec 1 14:28 /antlr4/runtime/Cpp/dist/libantlr4-runtime.so.4.9.3
CodePudding user response:
You can specify the directory with option -L and the library file with its abbreviated form (no lib prefix, no .so.xxx suffix):
g *.o -L /antlr4/runtime/Cpp/dist -lantlr4-runtime