file format not recognized; treating as linker script - c

I am trying to run the C files downloaded from here as follows :
gcc main.c docs_file.txt ksg_file.txt
However, I receive the following error:
/usr/bin/ld:docs_file.txt: file format not recognized; treating as linker script
/usr/bin/ld:docs_file.txt:2: syntax error
collect2: ld returned 1 exit status
I am not sure what the problem is.
Update 1:
I get the following errors while compiling:
gcc main.c -o ksg
/tmp/cc4H83rG.o: In function `main':
main.c:(.text+0xa5): undefined reference to `stree_new_tree'
main.c:(.text+0xe0): undefined reference to `stree_add_string'
main.c:(.text+0x2a7): undefined reference to `stree_match'
main.c:(.text+0x38f): undefined reference to `int_stree_set_idents'
main.c:(.text+0x422): undefined reference to `int_stree_get_parent'
main.c:(.text+0x47b): undefined reference to `int_stree_get_suffix_link'
/tmp/cc4H83rG.o: In function `count_freq':
main.c:(.text+0x96d): undefined reference to `int_stree_set_idents'
main.c:(.text+0x9a8): undefined reference to `stree_get_num_leaves'
main.c:(.text+0xa91): undefined reference to `int_stree_set_idents'
/tmp/cc4H83rG.o: In function `select_feature':
main.c:(.text+0xb34): undefined reference to `int_stree_set_idents'
main.c:(.text+0xbe7): undefined reference to `stree_get_num_children'
main.c:(.text+0xc47): undefined reference to `int_stree_get_parent'
main.c:(.text+0xc67): undefined reference to `int_stree_set_idents'
main.c:(.text+0xc94): undefined reference to `int_stree_get_parent'
main.c:(.text+0xdbb): undefined reference to `int_stree_get_suffix_link'
main.c:(.text+0xddb): undefined reference to `int_stree_set_idents'
main.c:(.text+0xe08): undefined reference to `int_stree_get_suffix_link'
collect2: ld returned 1 exit status

The tarball you linked to contains source code. To run the code you need to compile it into an executable. You can then run the executable if the compilation succeeds.
Here are the files you should have to start with, directly from the tar file:
$ ls
ksg main.c sample_ksgs.txt stree.h
ksg.exe sample_docs.txt stree.c stree.txt
Compile
First we'll compile the program. The -o ksg names the executable ksg. When gcc displays nothing that means it succeeded without any errors or warnings.
$ gcc -o ksg main.c stree.c
Run
Now we can run the ksg executable we just created. The command-line syntax is ./ksg <arguments>. For example, we can ask for help with ./ksg -?:
$ ./ksg -?
Dell Zhang, Wee Sun Lee.
Extracting Key-Substring-Group Features for Text Classification.
In Proceedings of the 12th ACM SIGKDD International Conference on
Knowledge Discovery and Data Mining (KDD),
Philadelphia, PA, Aug 2006.
Usage: ksg [options] docs_file ksgs_file
Options:
-? -> help
-s [0,1] -> assume white-spaces are word delimiters
(default 1)
-l [2..] -> the minimum frequency
(default 2)
-h [l..] -> the maximum frequency
(default 8,000)
-b [2..] -> the minimum number of branches
(default 2)
-p (0..1] -> the maximum parent-child conditional probability
(default 1.0)
-q (0..1] -> the maximum suffix-link conditional probability
(default 1.0)
Arguments:
docs_file -> the input file with each line as a raw document
ksgs_file -> the output file with each line as a bag of ksg features

Usually, gcc can compile only .c files - which, by convention, hold C code inside them.
.txt files are usually plain text. For human eyes only.
Try
gcc *.c

With C, you don't run a program using the compiler.
You first compile the C file to a binary (gcc main.c -o binary).
Then you execute it (./binary docs_file.txt ksg_file.txt).

Related

Installing AODV protocol on Raspberry pi (https://github.com/erimatnor/aodv-uu)

I'm trying to install AODV protocol on Raspberry pi. After completing git clone from "https://github.com/erimatnor/aodv-uu" when I tried to do "make" and I am getting below error. Expecting your suggestion. Thank you!
make
gcc -Wall -O3 -g -DDEBUG -DCONFIG_GATEWAY -DDEBUG -o aodvd main.o list.o debug.o timer_queue.o aodv_socket.o aodv_hello.o aodv_neighbor.o aodv_timeout.o routing_table.o seek_list.o aodv_rreq.o aodv_rrep.o aodv_rerr.o nl.o locality.o
aodv_neighbor.o: In function neighbor_add':
/home/pi/aodv-uu/aodv_neighbor.c:68: undefined reference tohello_update_timeout'
aodv_timeout.o: In function route_discovery_timeout':
/home/pi/aodv-uu/aodv_timeout.c:98: undefined reference tort_table_update_timeout'
aodv_rreq.o: In function rreq_route_discovery':
/home/pi/aodv-uu/aodv_rreq.c:460: undefined reference tort_table_update_timeout'
aodv_rreq.o: In function rreq_local_repair':
/home/pi/aodv-uu/aodv_rreq.c:521: undefined reference tort_table_update_timeout'
aodv_rrep.o: In function rrep_forward':
/home/pi/aodv-uu/aodv_rrep.c:231: undefined reference tort_table_update_timeout'
nl.o: In function nl_kaodv_callback':
/home/pi/aodv-uu/nl.c:282: undefined reference tort_table_update_timeout'
collect2: error: ld returned 1 exit status
Makefile:112: recipe for target 'aodvd' failed
make: *** [aodvd] Error 1
The code available from sourceforge is the same code that is on github. If you download the archive, you'll see that the latest modification date of any file there is 2010. Given the age of this code, I wouldn't be surprised to find that things simply don't work anymore.
However, here's a quick workaround for your problem. The root cause appears to be that the problem functions, like rt_table_update_timeout, are declared as inline, but that information seems to get lost somewhere in the build process such that other object files are trying to reference these as non-inline functions.
You can avoid this by opening defs.h, looking for this line:
#define NS_INLINE inline
And replace it with:
#define NS_INLINE
This will allow aodvd to compile correctly (make aodvd). On my system, the kernel module will subsequently fail to compile:
cc1: fatal error: /lib/modules/4.13.15-100.fc25.x86_64/build/include/linux/modversions.h: No such file or directory
As far as I can tell, the modversions.h file is no longer produced by modern Linux kernels.

Working with Influxdb connection in C Programming raising undefined referece to influxdb_client_new

This is main.c file I am trying to work with influxdb library I hope I installed it clearly with my knowledge here are the screen shots of library
This is linked library
This is the path of the library
This is the code file
#include <influxdb/influxdb.h>
int main() {
int status;
s_influxdb_client *client = influxdb_client_new("xxxxxxxxxx", "influxdb", "xxxxxxxxxxxxxx", "", 0);
status = influxdb_create_database(client, "toto");
influxdb_client_free(client);
return status != 201;
}
This is how I executing the command in gcc to compile and run
gcc -I/usr/local/include/ -L/usr/local/lib -linfluxdb -o john john.c
Even though I included the library it raising undefined reference
This is what my error is
/tmp/cce9K1Kh.o: In function `main':
john.c:(.text+0x23): undefined reference to `influxdb_client_new'
john.c:(.text+0x38): undefined reference to `influxdb_create_database'
john.c:(.text+0x47): undefined reference to `influxdb_client_free'
collect2: error: ld returned 1 exit status
This is where I found library and Followed the instructions in Read Me file Everything is performed smooth Influxdb
Please let me know if you need more information
The influxdb README.md is b0rken. Ordering of command-line arguments to gcc (or the linker actually) matters; the -linfluxdb must come after your john.c on the command line.
Thus, try compiling/linking with with
gcc -I/usr/local/include/ -L/usr/local/lib -o john john.c -linfluxdb

gcc static library compilation

i have made a static library using the ar command after an object creation using gcc -o file.o -c file.c.
Now i'm trying to use the gcc to link this library in the compilation with a command similar to this
gcc -I /PathInclude -L /PathStaticLib -lm \
-std=c99 -o file file.o -lstatic_library_name
with static_library_name i mean that the file is named
libstatic_library_name.a
Since the files structure is quite complex (because basically in the compiling i also substitute some macro definition etc) i don't post all the code, do you have any thought on what is going on? if not what kind of info could i provide to you in order to help me?
PS. there aren't a lot o files, but the internal structure is a bit complicated to explain in few words, so... let me know what do you need.
I can give you the make file content if you need, is not complicated.
PS. The command is...
gcc -I../CModels -L../CModels/ -std=c99 -o ref_approx_bs3_log2_4_4_1ulp_arch1
ref_approx_bs3_log2_4_4_1ulp_arch1.o -lm -lmy_float
The error is
ref_approx_bs3_log2_4_4_1ulp_arch1.o: In function `cogen_fp_bs3_log2_4_4_1ulp_arch1':
ref_approx_log2.c:(.text+0x2229): undefined reference to `cast'
ref_approx_log2.c:(.text+0x22d0): undefined reference to `cast'
ref_approx_log2.c:(.text+0x22f7): undefined reference to `cast'
ref_approx_log2.c:(.text+0x232e): undefined reference to `sumFP'
ref_approx_log2.c:(.text+0x2350): undefined reference to `diffFP'
ref_approx_log2.c:(.text+0x2375): undefined reference to `mulFP'
ref_approx_log2.c:(.text+0x239c): undefined reference to `sumFP'
collect2: ld returned 1 exit status
Using
nm my_float.a
the output is
my_float.o:
0000000000000ca8 T _Z11castToFixedyPyyyy
0000000000000a0c T _Z12splitIntFracyPyS_yy
0000000000000324 T _Z28rightShift_and_round2NearestyyPyyy
000000000000005c T _Z3ldzy
0000000000000132 T _Z3mulyyy
000000000000048a T _Z4castyPyyyyy
0000000000000000 T _Z4maxuyy
000000000000002e T _Z4minuyy
00000000000014dc T _Z5mulFPyyPyyy
0000000000000cc2 T _Z5sumFPyyPyyy
000000000000147a T _Z6diffFPyyPyyy
0000000000000300 T _Z9ldzFormatyy
U __gxx_personality_v0
So i guess the library .a is ok...
As per the gcc manual, AFAIR, there should be no space in between -L or -I and the path. Change your command to
.. -I/PathInclude -L/PathStaticLib ...
Error says that the references to cast, sumFP, diffFP , mulFP are not defined. Need to make sure that they are defined in the library.

Error compiling Rglpk on Windows

I need to use the R package Rglpk in a project and need to modify the package - in particular, I need to add a time limit control parameter option to the interface (it is a option in GLPK v4.5.2 itself, but Rglpk 0.5-2 does not support this parameter). This will allow R to call GLPK and limit the search time to be user specified (i.e., search time <= t).
I have modified Rglpk code and have successfully compiled the package on Mac OS X v10.9.2 and verified that it worked as expected. My project needs to run on Windows and I have not been able to compile the modified Rglpk package, or for that matter the unmodified package (Rglpk 0.5-2), on Windows. I have tried uploading the original package to Win Builder (http://win-builder.r-project.org/), but I have received the same errors.
The following is a summary of what I have done on Windows 7 (my machine):
(1) Download the Rglpk 0.5-2 package source from http://cran.r-project.org/web/packages/Rglpk/index.html
(2) Unzip the file to a directory. All the code is in a directory called Rglpk.
(3) Start RStudio v0.98.490. I have devtools v1.4.1 installed, Rtools v3.1 installed, and R v3.0.2
(4) Open a new project and select the Rglpk directory mentioned in (2).
(5) Under the 'Build' menu, select 'Build and Reload'. The result of this is that the package compiles and is loaded:
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (Rglpk)
(6) Under the 'Build' menu, select 'Check Package'. The result is that the installation fails. The log file is shown below.
I have tried to compile another package that has C code and have not been able to compile it either. The package I tried to compile is devtools v1.5 The error that came back in that case is 'LoadLibrary failure: %1 is not a valid Win32 application.'
Does anyone have any experience compiling R packages on Windows that include C code? I have been able to compile packages that involve only R code, but it seems C code is troublesome.
Any help would be appreciated.
Log File
* using R version 3.0.2 (2013-09-25)
* using platform: x86_64-w64-mingw32 (64-bit)
* using session charset: ISO8859-1
* checking for file 'Rglpk/DESCRIPTION' ... OK
* this is package 'Rglpk' version '0.5-2'
* checking package namespace information ... OK
* checking package dependencies ... OK
* checking if this is a source package ... NOTE
Found the following apparent object files/libraries:
src/GLPK/alloc.o src/GLPK/amd/amd_1.o src/GLPK/amd/amd_2.o
src/GLPK/amd/amd_aat.o src/GLPK/amd/amd_control.o
src/GLPK/amd/amd_defaults.o src/GLPK/amd/amd_dump.o
src/GLPK/amd/amd_info.o src/GLPK/amd/amd_order.o
src/GLPK/amd/amd_post_tree.o src/GLPK/amd/amd_postorder.o
src/GLPK/amd/amd_preprocess.o src/GLPK/amd/amd_valid.o
src/GLPK/bignum.o src/GLPK/cfg.o src/GLPK/cfg1.o
src/GLPK/colamd/colamd.o src/GLPK/dmp.o src/GLPK/env.o
src/GLPK/error.o src/GLPK/ffalg.o src/GLPK/fhv.o src/GLPK/fhvint.o
src/GLPK/glpapi01.o src/GLPK/glpapi02.o src/GLPK/glpapi03.o
src/GLPK/glpapi04.o src/GLPK/glpapi05.o src/GLPK/glpapi06.o
src/GLPK/glpapi07.o src/GLPK/glpapi08.o src/GLPK/glpapi09.o
src/GLPK/glpapi10.o src/GLPK/glpapi11.o src/GLPK/glpapi12.o
..... (more lines are here, I have removed them for brevity)
src/GLPK/triang.o src/GLPK/wclique.o src/GLPK/wclique1.o
src/GLPK/zlib/adler32.o src/GLPK/zlib/compress.o
src/GLPK/zlib/crc32.o src/GLPK/zlib/deflate.o src/GLPK/zlib/gzclose.o
src/GLPK/zlib/gzlib.o src/GLPK/zlib/gzread.o src/GLPK/zlib/gzwrite.o
src/GLPK/zlib/inffast.o src/GLPK/zlib/inflate.o
src/GLPK/zlib/inftrees.o src/GLPK/zlib/trees.o
src/GLPK/zlib/uncompr.o src/GLPK/zlib/zio.o src/GLPK/zlib/zutil.o
Object files/libraries should not be included in a source package.
* checking if there is a namespace ... OK
* checking for executable files ... OK
* checking for hidden files and directories ... OK
* checking for portable file names ... OK
* checking whether package 'Rglpk' can be installed ... ERROR
Installation failed.
The contents of the 00install.out file are:
* installing *source* package 'Rglpk' ...
** libs
*** arch - i386
gcc -m32 -I"C:/PROGRA~1/R/R-30~1.2/include" -DNDEBUG -IGLPK -IGLPK/amd -IGLPK/colamd -IGLPK/minisat -IGLPK/proxy -IGLPK/zlib -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O3 -Wall -std=gnu99 -mtune=core2 -c Rglpk_initialize.c -o Rglpk_initialize.o
gcc -m32 -I"C:/PROGRA~1/R/R-30~1.2/include" -DNDEBUG -IGLPK -IGLPK/amd -IGLPK/colamd -IGLPK/minisat -IGLPK/proxy -IGLPK/zlib -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O3 -Wall -std=gnu99 -mtune=core2 -c Rglpk_read_file.c -o Rglpk_read_file.o
Rglpk_read_file.c: In function 'Rglpk_read_file':
Rglpk_read_file.c:84:6: warning: 'status' may be used uninitialized in this function [-Wuninitialized]
Rglpk_read_file.c: In function 'Rglpk_retrieve_MP_from_file':
Rglpk_read_file.c:192:6: warning: 'status' may be used uninitialized in this function [-Wuninitialized]
gcc -m32 -I"C:/PROGRA~1/R/R-30~1.2/include" -DNDEBUG -IGLPK -IGLPK/amd -IGLPK/colamd -IGLPK/minisat -IGLPK/proxy -IGLPK/zlib -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O3 -Wall -std=gnu99 -mtune=core2 -c Rglpk_solve.c -o Rglpk_solve.o
Rglpk_solve.c: In function 'R_glp_solve':
Rglpk_solve.c:25:10: warning: variable 'kl' set but not used [-Wunused-but-set-variable]
gcc -m32 -shared -s -static-libgcc -o Rglpk.dll tmp.def Rglpk_initialize.o Rglpk_read_file.o Rglpk_solve.o GLPK/libglpk.a -Ld:/RCompile/CRANpkg/extralibs64/local/lib/i386 -Ld:/RCompile/CRANpkg/extralibs64/local/lib -LC:/PROGRA~1/R/R-30~1.2/bin/i386 -lR
c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/bin/ld.exe: i386:x86-64 architecture of input file `GLPK/libglpk.a(glpmpl04.o)' is incompatible with i386 output
c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/bin/ld.exe: i386:x86-64 architecture of input file `GLPK/libglpk.a(error.o)' is incompatible with i386 output
c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/bin/ld.exe: i386:x86-64 architecture of input file `GLPK/libglpk.a(glpmpl03.o)' is incompatible with i386 output
c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/bin/ld.exe: i386:x86-64 architecture of input file `GLPK/libglpk.a(alloc.o)' is incompatible with i386 output
c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/bin/ld.exe: i386:x86-64 architecture of input file `GLPK/libglpk.a(glpenv07.o)' is incompatible with i386 output
c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/bin/ld.exe:
.....
Error: 64-bit reloc in dll
Error: 64-bit reloc in dll
Error: 64-bit reloc in dll
.....
Rglpk_initialize.o:Rglpk_initialize.c:(.text+0x33): undefined reference to `glp_term_hook'
Rglpk_initialize.o:Rglpk_initialize.c:(.text+0x44): undefined reference to `glp_version'
Rglpk_read_file.o:Rglpk_read_file.c:(.text+0x10): undefined reference to `glp_delete_prob'
Rglpk_read_file.o:Rglpk_read_file.c:(.text+0x4f): undefined reference to `glp_term_out'
Rglpk_read_file.o:Rglpk_read_file.c:(.text+0x60): undefined reference to `glp_delete_prob'
Rglpk_read_file.o:Rglpk_read_file.c:(.text+0x65): undefined reference to `glp_create_prob'
.....
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0x4326): undefined reference to `strcpy'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0x4d39): undefined reference to `strcpy'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0x4dc5): undefined reference to `strcpy'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0x4e05): undefined reference to `floor'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0x4e16): undefined reference to `floor'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0x502e): undefined reference to `floor'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0x50e2): undefined reference to `sprintf'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0x5111): undefined reference to `sprintf'
.....
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0x990): undefined reference to `exp'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0x9e0): undefined reference to `log'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0xa30): undefined reference to `log10'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0xaee): undefined reference to `sin'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0xb4e): undefined reference to `cos'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0xb65): undefined reference to `atan'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0xb79): undefined reference to `atan2'
.....
GLPK/libglpk.a(deflate.o):deflate.c:(.text+0x2ec0): undefined reference to `memcpy'
GLPK/libglpk.a(deflate.o):deflate.c:(.text+0x2ed5): undefined reference to `memcpy'
GLPK/libglpk.a(deflate.o):deflate.c:(.text+0x2ee7): undefined reference to `memcpy'
GLPK/libglpk.a(zutil.o):zutil.c:(.text+0x47): undefined reference to `malloc'
GLPK/libglpk.a(zutil.o):zutil.c:(.text+0x54): undefined reference to `free'
collect2: ld returned 1 exit status
ERROR: compilation failed for package 'Rglpk'
It looks like a couple things are going wrong:
Object files are getting pre-compiled, but not cleaned out.
Because these object files are being pre-compiled, and it looks like they were compiled for 64-bit architecture, when you try to use these in a 32-bit build, the installation process barfs.
The fix here is going to be deleting all of those *.o files (they need to be compiled as part of the R CMD build step, I imagine), and the resulting tarball can then be R CMD checked.
You should consider installing a more up-to-date version of RStudio and devtools, and ensure you use devtools to handle the build process -- it might be able to help you out here.

I can't compile this code of mongoose web server's sample example

Short Intro :- (GCC version 4.6.3, OS-Ubuntu 12.04 ,working around mongoose web server program so when I run "make" command to compile and install mongoose , it has done the task fine ).
[Part 1 of question]
This question is in reference to this post on stackowerflow.
mongoose web server helloworld program
Valenok has answered on this post by giving a link to hello sample program.
basically, I am trying to compile the sample hello program code given on this link :-
http://code.google.com/p/mongoose/source/browse/examples/hello.c
and put this code in already compiled directory of mongoose.(directory has mongoose.h file)
Following is command line output for my compilation of hello program.
akshay#akshay-Inspiron-N5010:~$ gcc mongoose/hello.c -o mongoose/hello
/tmp/ccroC5Z6.o: In function `callback':
hello.c:(.text+0x32): undefined reference to `mg_get_request_info'
hello.c:(.text+0x96): undefined reference to `mg_printf'
/tmp/ccroC5Z6.o: In function `main':
hello.c:(.text+0xee): undefined reference to `mg_start'
hello.c:(.text+0x103): undefined reference to `mg_stop'
collect2: ld returned 1 exit status
akshay#akshay-Inspiron-N5010:~$
[Part 2 of question]
Now , I find implementations of mg_stop , mg_start,mg_printf and mg_get_request_info in mongoose.c file , so I compile mongoose.c file with -c option as :
gcc -c -o mongoose.o mongoose.c
I think my question is similar to :-
undefined reference to function declared in *.h file
but then when I link libmongoose.so with -L option on gcc I get following errors:-
(libmongoose.so is present in same directory ,my cwd)
akshay#akshay-Inspiron-N5010:~/mongoose$ gcc -L libmongoose.so -o hello hello.o mongoose.o
mongoose.o: In function `mg_start_thread':
mongoose.c:(.text+0x1369): undefined reference to `pthread_create'
mongoose.o: In function `load_dll':
mongoose.c:(.text+0xa955): undefined reference to `dlopen'
mongoose.c:(.text+0xa9b4): undefined reference to `dlsym'
collect2: ld returned 1 exit status
also , I continue to get above ^^ errors when I compile without using libmongoose.so
[EDIT] : added -pthread option on gcc, still shows errors :-
mongoose.o: In function load_dll':
mongoose.c:(.text+0xa955): undefined reference todlopen'
mongoose.c:(.text+0xa9b4): undefined reference to `dlsym'
collect2: ld returned 1 exit status
For part 1 and part 2 of my question : I want to get rid of these errors and successfully run hello.c program sample successfully.
Thanks in advance .
The -L option is not used for linking against a library, it's used for specifying a search path for dynamic libraries. To link against a specific library, use -l. However, you don't need to link against both of mongoose.o and libmongoose.so, either one is sufficient.
On Linux, you also have to link against the pthread and the dynamic loading library as well, because despite being part of the C standard library, they're not present in libc.so. One more thing to pay attention to is that recent versions of binutils (specifically, of ld) require that the libraries and object files be specified in the order the symbols depend on each other, i. e. libraries must go to the end of the command line.
All in all, use one of the following commands:
gcc -o hello hello.o mongoose.o -ldl -lpthread
or
gcc -L. -o hello hello.o -lmongoose -ldl -lpthread

Resources