Home > Software engineering >  lexbor C: How to correctly install and use on CentOS 7
lexbor C: How to correctly install and use on CentOS 7

Time:10-20

Goal:

To correctly install and use lexbor on CentOS 7.

Current output:

When I go to compile a program using lexbor with the command gcc example.c -liblexbor -std=c99 -o example on CentOS 7, the following error is received:

[user@localhost]$ gcc example.c -liblexbor -std=c99 -o example
/usr/bin/ld: cannot find -liblexbor
collect2: error: ld returned 1 exit status

Details:

I installed lexbor for CentOS 7 following the instructions found at this link for CentOS 7. It seems that the linker cannot find the library. I ran the command ldconfig -p to find the path of the lexbor lib, which returned:

liblexbor.so.2 (libc6,x86-64) => /lib64/liblexbor.so.2

With the path found, I then ran the following two commands I recompiled using the same compilation command as the one seen above, but the same error message was shown:

[user@localhost]$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/lib64/liblexbor.so.2
[user@localhost]$ sudo ldconfig

I then tried a different approach to see if I could solve this issue by embedding the path into the compilation command, but this resulted in the same output:

gcc -L/lib64/ -liblexbor -std=c99 example.c -o example

Please note: before deciding to post this question, I consulted the following resources:

  1. usr/bin/ld: cannot find -l<nameOfTheLibrary>
  2. https://askubuntu.com/questions/1007591/usr-bin-ld-cannot-find-lopencl

Summary question:

q1. How can this error be solved when trying to compile a C program using lexbor on CentOS 7?

CodePudding user response:

You're specifying the library name incorrectly. For a given library file named liblibrary.so, the correct option is -l library. So you need to compile like this:

gcc example.c -llexbor -std=c99 -o example
  • Related