2

I am trying to compile main.c with a static library and header files on an Ubuntu server using gcc and ssh using Terminal on Mac. I uploaded the library file and specified it with -L option and specified the header files using the -I option.

I tried using:

gcc main.c -L/Libraries/lib/libRNA.a -lRNA  -ILibraries/include/ViennaRNA

It comes out with:

/usr/bin/ld: cannot find -lRNA

collect2: error: ld returned 1 exit status

Ponnarasu
  • 635
  • 1
  • 11
  • 24
Edenapple
  • 23
  • 1
  • 4

3 Answers3

2

-L expects a directory as argument. You're passing the name of the library.

Just do:

gcc main.c -L/Libraries/lib -lRNA -ILibraries/include/ViennaRNA

or link with the absolute path of the .a file directly:

gcc main.c /Libraries/lib/libRNA.a -ILibraries/include/ViennaRNA
Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
  • I tried the first one and it said: /usr/bin/ld: cannot find -lRNA collect2: error: ld returned 1 exit status I tried the second one and it said: gcc: error: /Libraries/lib/libRNA.a: No such file or directory – Edenapple Dec 10 '16 at 19:33
  • I changed the directory and it works, thanks. However it says "file not recognized: File format not recognized". probably the .a file is created using the "make" command in my Mac, which is incompatible with ubuntu – Edenapple Dec 10 '16 at 19:50
  • Yes you have to rebuild the .a file on ubuntu. – Jean-François Fabre Dec 10 '16 at 21:19
1

The -L option specifies a directory where the library file is.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
0

The -L option to gcc (which gets actually passed to ld) is expecting a directory (in which further -l options are seeked).

The -I option is expecting a directory containing included header files.

So you want

 gcc -Wall -g main.c -L/Libraries/lib/ -lRNA -ILibraries/include/ViennaRNA

You really want all warnings (-Wall) and debug information (-g) to be able to use the gdb debugger.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547