Use -l:
instead of -l
. For example -l:libXYZ.a
to link with libXYZ.a
. Notice the lib
and .a
are written out, as opposed to -lXYZ
which would auto-expand to libXYZ.so
/libXYZ.a
.
It is an option of the GNU ld
linker:
-l namespec
… If namespec is of the form:filename
,ld
will search the library path for a file called filename, otherwise it will search the library path for a file calledlibnamespec.a
. … on ELF … systems,ld
will search a directory for a library calledlibnamespec.so
before searching for one calledlibnamespec.a
. … Note that this behavior does not apply to:filename
, which always specifies a file called filename.”
(Since binutils 2.18)
Note that this only works with the GNU linker. If your ld
isn’t the GNU one you’re out of luck.
Related Posts:
- C Linking Error: undefined reference to ‘main’
- “Multiple definition of” C++ compiler error
- libpthread.so.0: error adding symbols: DSO missing from command line
- Why does fatal error “LNK1104: cannot open file ‘C:\Program.obj'” occur when I compile a C++ project in Visual Studio?
- gcc: undefined reference to
- File format not recognized; treating as linker script using GCC
- What is the difference between g++ and gcc?
- Differences between arm64 and aarch64
- g++ ld: symbol(s) not found for architecture x86_64
- Convert char to int in C and C++
- gcc makefile error: “No rule to make target …”
- gcc makefile error: “No rule to make target …”
- How does #include
work in C++? - Undefined reference to vtable
- Expected initializer before function name
- Inheriting constructors
- How do I install gcc on cygwin?
- what is stack smashing (C)?
- Undefined reference to vtable
- C ++ error: a expected initializer before [function name]
- Inheriting constructors
- gcc: error: unrecognized command line option
- setup script exited with error: command ‘x86_64-linux-gnu-gcc’ failed with exit status 1
- warning: incompatible implicit declaration of built-in function ‘xyz’
- undefined reference to ‘std::cout’
- fatal error: Python.h: No such file or directory
- Fatal error: iostream: No such file or directory in compiling C program using GCC
- MinGW: “gcc is not recognized as an internal or external command”
- How do I force make/GCC to show me the commands?
- C: linker command failed with exit code 1
- Why am I getting “undefined reference to sqrt” error even though I inclu de math.h header?
- Compiling a C++ program with gcc
- conflicting types error when compiling c program using gcc
- What is a file with extension .a?
- Visual C++ find line causing “Debug Assertion failed”
- Why am I getting “undefined reference to sqrt” error even though I include math.h header?
- Why am I getting “undefined reference to sqrt” error even though I include math.h header?
- What is the “Illegal Instruction: 4” error and why does “-mmacosx-version-min=10.x” fix it?
- gcc/g++: “No such file or directory”
- error: use of deleted function
- Multiple definition of … linker error
- C compile : collect2: error: ld returned 1 exit status
- Installing GCC on macOS Catalina
- CMake error at CMakeLists.txt:30 (project): No CMAKE_C_COMPILER could be found
- (.text+0x20): undefined reference to `main’ and undefined reference to function
- Interpreting valgrind error Invalid write of size 4
- cannot declare variable ‘’ to be of abstract type ‘’
- difference between
and - OS X 10.9.2: checking whether the C compiler works… no
- Warning/error “function declaration isn’t a prototype”
- Error: initializer element is not computable at load time
- warning: initializer element is not computable at load time
- Debug vs Release in CMake
- Debug vs Release in CMake
- Compiling a .C file: Undefined symbols for architecture x86_64
- Static linking vs dynamic linking
- gcc error : undefined reference to `itoa’
- What is the difference between gcc/g++ and cc1/cc1plus?
- Removing trailing newline character from fgets() input
- What does the fpermissive flag do?
- How to repair warning: missing braces around initializer?
- Why do I get “cast from pointer to integer of different size” error?
- What happens during a “relocation has invalid symbol index” error?
- g++ output: file not recognized: File format not recognized
- Update GCC on OSX
- What does this GCC error “… relocation truncated to fit…” mean?
- gcc error: wrong ELF class: ELFCLASS64
- Undefined reference to main – collect2: ld returned 1 exit status
- GCC -fPIC option
- error: unknown type name ‘bool’
- Where is the
header file on Linux? Why can’t I find ? - How do I compile the asm generated by GCC?
- gcc -g :what will happen
- make -j 8 g++: internal compiler error: Killed (program cc1plus)
- C Unknown type name ‘my_structure’
- Warning : overflow in implicit constant conversion
- Make Error 127 when running trying to compile code
- Gcc error: gcc: error trying to exec ‘cc1’: execvp: No such file or directory
- gcc 4.8 on MAC OS X 10.8 throws “Undefined symbols for architecture x86_64: “
- cc1.exe System Error – libwinpthread-1.dll missing – But it isn’t
- Fatal error: iostream: No such file or directory in compiling C program using GCC
- How to Check the Version of my gcc?
- typedef fixed length array
- Make / gcc cryptic error 2: how to have more information?
- How to solve static declaration follows non-static declaration in GCC C code?
- Linker error: “linker input file unused because linking not done”, undefined reference to a function in that file
- GCC: Array type has incomplete element type
- I don’t understand -Wl,-rpath -Wl,
- How to compile C program on command line using MinGW?
- How to add a default include path for GCC in Linux?
- Compiler gcc:error; no such file or directory