How to compile gcc with static library?

Ice

I have static library lib.a and in all tutorials using:

gcc -o main main.o -L. -lib

But I cant, I have errors:

    /usr/bin/ld: cannot find -lib
collect2: error: ld returned 1 exit status

I need to use:

gcc -o main main.o -L. -lib.a

Why? What should I do to repair it ?

MicroVirus

From the documentation of gcc -l:

-llibrary:

The linker searches a standard list of directories for the library, which is actually a file named liblibrary.a. The linker then uses this file as if it had been specified precisely by name.

...

The only difference between using an -l option and specifying a file name is that -l surrounds library with ‘lib’ and ‘.a’ and searches several directories.

So you cannot use -l with a library named 'lib.a'. Use 'lib.a' without the -l to include it. Of course, you cannot use -L then to set the directories to be searched for this particular library.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to compile gcc with static library?

From Dev

How to compile gcc with shared library?

From Dev

How to compile gcc with shared library?

From Dev

How to compile a static library with Codelite 11.0.0?

From Dev

How to use static library with gcc under linux

From Dev

GCC linked library for compile

From Dev

FPC Compile as Static Library

From Dev

Compile as static and dynamic library

From Dev

GCC linking a static library

From Dev

How to compile C++ REST SDK into a static library on Ubuntu Linux?

From Dev

gcc - A static library with undefined symbols?

From Dev

How to compile with gcc in php?

From Java

How to CMake compile a library as part of my app's source and not as static/shared library?

From Dev

Unable to compile the nn library - is gcc not installed?

From Dev

How to compile CLOGS library

From Dev

How to compile CLOGS library

From Dev

Compile with linking against static and dynamic library for OpenSSL

From Dev

Compile Swift script with static Swift core library

From Dev

Cross-compile for armhf and install a static library

From Dev

Cross-compile for armhf and install a static library

From Dev

Generic Gfortran Makefile to compile with static library

From Dev

Extracting gcc version information from static library

From Dev

Unable to use VisualStudio made static library with GCC

From Dev

How to page the compile messages of GCC?

From Dev

How to compile with gcc inside OpenWRT

From Dev

How to page the compile messages of GCC?

From Dev

How to compile and run using GCC?

From Dev

How to compile with gcc inside OpenWRT

From Dev

How do you compile a static library that has a 3rd party dependency without including the dependency?

Related Related

HotTag

Archive