lexbor C: How to correctly install and use on CentOS 7 - c

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:
usr/bin/ld: cannot find -l<nameOfTheLibrary>
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?

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

libtiff build undefined reference to `_imp__TIFFOpen' error

probably this is a trivial newbie question, however, I can't figure out how to solve it.
I'm trying to build a test program using libtiff (test program copied from here). I've downloaded the static library libtiff.lib as well as the required header file tiffio.h. When I compile the main c function with no problem I have a main.o file. When I try to link main.o with libtiff using this command
gcc -g -Wall -o test.exe ./libtiff.lib ./test.o
I have this error:
undefined reference to `_imp__TIFFOpen'
I've looked into the lib file with nm -A libtiff.lib command and I can find this line
libtiff.lib:libtiff3.dll:00000000 I __imp__TIFFOpen
but it has 2 leading underscores instead of 1 as required by the linker. I'm using mingw on Windows 7 and all the required files are in the same directory.
No clue how to link with no errors.
Thanks in advance.
As suggested in the the comments, it was sufficient to invert the order of objects passed as arguments:
gcc -g -Wall -o test.exe ./test.o ./libtiff.lib

libxml for c program in ubuntu

I want to use libxml2 as parser for a c program on a system with ubuntu. I used the following command to install libxml2:
sudo apt-get install -y libxml2-dev
I try to compile the following file: http://xmlsoft.org/examples/reader1.c
My makefile looks like this:
xml_reader: xml_reader.o
gcc -o xml_reader xml_reader.o -lxml2 -lm
xml_reader.c: xml_reader.c
gcc -c xml_reader.c -I/usr/include/libxml2
But sadly I get the following response:
fatal error: libxml/xmlreader.h: No such file or directory
Did I miss something, which I had to do before compiling or am I even using the right -l argument?
The target of your second Makefile rule should be xml_reader.o and not xml_reader.c. Right now make is using a default rule instead which does not make use of -I/usr/include/libxml2 and thus gcc cannot find the required header.

Is there a way to find the root of this error?

Im trying to compile some files with this given gcc command on a server cluster through Mac terminal:
gcc -o driver -std=c11 -Wall -W -ggdb3 driver.c ASMParser.c ParseResult.c Generate.o Grader.o
And get this error:
/usr/bin/ld:Grader.o: file format not recognized; treating as linker script
/usr/bin/ld:Grader.o:1: syntax error
collect2: error: ld returned 1 exit status
but its not very helpful considering Grader.o is a file I didn't even modify, it was provided by the teacher.
Any help on how to fix this? I have compiled it successfully using that gcc command before but after I added a few more implementation details in ASMParser.c it started giving me this error. Im expecting it to create a file called "driver" that I can run like this:
./driver "test file" "results.txt"

Linking fftw-3.3.6-pl2 while compiling my file using gcc

I'm trying to run a simple code that includes the fftw library. I know the code is right as it is provided as a test code by the authors. This is what I typed during compilation:
gcc my file.c -L/home/ankit/Desktop/fftw-3.3.6-pl2/lib/
-I/home/ankit/Desktop/fftw-3.3.6-pl2/include/ -lfftw -lm
I get the errors:
myfile.c: (.Text+0x2c):. undefined reference to 'fftw_plan_dft_2d'
collect2: ld returned 1 exit status
It wasn't a linking problem, installation was faulty and I had to use 'sudo make install' to get the permission for the installation to be successful. I could link it with 'gcc test.c -lfftw3 -lm' after. Thanks for your suggestions!

Shared library creation in LINUX throws error

I've ten ".o" files in a directory.i want to combine them as a shared lib (.so) file.
For doing so,I am issuing following command
#gcc -shared *.o -o abc.so
but it throws following error message:
No command '-shared' found, did you mean:
Command 'gshared' from package 'gshare' (universe)
-shared: command not found
What could be the possible reason? Anything wrong with the command?
Any help ?
I agree with Chen Levy. It looks like gcc is either a stange version or not what you think it is. When I do:
gcc -shared *.o -o abc.so
I get the desired reponse. Try echo, or even:
which gcc
to try and see what's really going on. PS: I Tested on Ubuntu 10.10

Resources