I am trying to compile some programs i have found on github. The repository is at the following URL:
[enter link description here][1]
https://github.com/iagox86/nbtool
I have little knowledge of C programs, however when i try to use GCC with the following command i receive errors.
the command i have tried is:
gcc -o dnslogger dnslogger.c
I receive the following error:
/tmp/ccLRFQbp.o: In function `dns_callback':
dnslogger.c:(.text+0x51): undefined reference to `dns_create_from_packet'
dnslogger.c:(.text+0x5f): undefined reference to `dns_create'
dnslogger.c:(.text+0x10e): undefined reference to `dns_add_question'
dnslogger.c:(.text+0x179): undefined reference to `dns_add_answer_A'
dnslogger.c:(.text+0x1dc): undefined reference to `dns_add_answer_AAAA'
dnslogger.c:(.text+0x214): undefined reference to `dns_to_packet'
dnslogger.c:(.text+0x236): undefined reference to `udp_send'
dnslogger.c:(.text+0x260): undefined reference to `dns_create_error_string'
dnslogger.c:(.text+0x282): undefined reference to `udp_send'
dnslogger.c:(.text+0x28e): undefined reference to `safe_free'
dnslogger.c:(.text+0x29a): undefined reference to `dns_destroy'
dnslogger.c:(.text+0x2a6): undefined reference to `dns_destroy'
/tmp/ccLRFQbp.o: In function `dns_poll':
dnslogger.c:(.text+0x2d7): undefined reference to `select_group_create'
dnslogger.c:(.text+0x304): undefined reference to `select_group_add_socket'
dnslogger.c:(.text+0x321): undefined reference to `select_set_recv'
dnslogger.c:(.text+0x336): undefined reference to `select_group_do_select'
/tmp/ccLRFQbp.o: In function `cleanup':
dnslogger.c:(.text+0x36b): undefined reference to `select_group_destroy'
dnslogger.c:(.text+0x37a): undefined reference to `safe_free'
dnslogger.c:(.text+0x384): undefined reference to `print_memory'
/tmp/ccLRFQbp.o: In function `main':
dnslogger.c:(.text+0x6ed): undefined reference to `safe_malloc_internal'
dnslogger.c:(.text+0x718): undefined reference to `winsock_initialize'
dnslogger.c:(.text+0x934): undefined reference to `dns_do_test'
dnslogger.c:(.text+0xaab): undefined reference to `udp_create_socket'
dnslogger.c:(.text+0xb5f): undefined reference to `drop_privileges'
collect2: error: ld returned 1 exit status
the repository has a Makefile file which i suspect is used to compile the programs, but i am not sure of the exact commands to use on ubuntu, i have tried some of the commands but i receive errors when using the supplied commands from the file.
the makefile is located here:
https://github.com/iagox86/nbtool/blob/master/Makefile
How can i compile these programs from ubuntu command line?
Just run make.
git clone https://github.com/iagox86/nbtool
cd nbtool
make
You need some programs to compile everything (samples) though.
(make will complain if they're missing on your system)
If you're more interested in the Makefile itself, use the links in the comments or read specific documentation for example Gnu Make
(I chose Gnu Make, as tags specify ubuntu explicitly)
Related
As you may imagine, it's a homework of Operating Systems and I'm asked to add function key Shift+F7 to show the number of running process.
I read the source code of command ps on GitHub (MINIX version 3.2.1) and try to implement a function that can finish the task in file /usr/src/servers/is/dmp_kernel.c. However, when I try to run make, it complains about undefined reference like
dmp_kernel.o: In function `running_proc_num':
dmp_kernel.c:(.text+0x1e): undefined reference to `chdir'
dmp_kernel.c:(.text+0x42): undefined reference to `fopen'
dmp_kernel.c:(.text+0x72): undefined reference to `fscanf'
dmp_kernel.c:(.text+0x8b): undefined reference to `fclose'
dmp_kernel.c:(.text+0xc4): undefined reference to `log10'
dmp_kernel.c:(.text+0xcc): undefined reference to `ceil'
dmp_kernel.c:(.text+0x119): undefined reference to `log10'
dmp_kernel.c:(.text+0x121): undefined reference to `ceil'
dmp_kernel.c:(.text+0x170): undefined reference to `fopen'
dmp_kernel.c:(.text+0x1bc): undefined reference to `fscanf'
dmp_kernel.c:(.text+0x1d3): undefined reference to `fclose'
dmp_kernel.c:(.text+0x210): undefined reference to `wait'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I've already include the headers like stdio.h, math.h, unistd.h, and sys/wait.h. In the answer to one Stack Overflow question, I learnt that the reason for this issue is that the linker doesn't link a complete C library under MINIX. However, I usually use CMake and really have no idea to solve such issue. I don't even know how to "explicitly" link the functions using make.
I really look forward for your help!
The Makefile looks like
.include <bsd.own.mk>
PROG= is
SRCS= main.c dmp.c dmp_kernel.c dmp_pm.c dmp_fs.c dmp_rs.c dmp_ds.c dmp_vm.c
DPADD+= ${LIBSYS}
LDADD+= -lsys
MAN=
BINDIR?= /sbin
CPPFLAGS.dmp_kernel.c+= -I${NETBSDSRCDIR}
CPPFLAGS.dmp_rs.c+= -I${NETBSDSRCDIR}
CPPFLAGS.dmp_vm.c+= -I${NETBSDSRCDIR}
# This setting must match the kernel's, as it affects the IRQ hooks table size.
.if ${USE_APIC} != "no"
CFLAGS+= -DUSE_APIC
.endif
.include <minix.service.mk>
I have been trying to compile and link a test file written in c and which can communicate with FMILibrary of JModelica. I was able to compile and link it and run it in linux systems. coming to the Windows, I am using mingw-64 compiler to compile and link the test file with FMILibrary, but I am getting undefined reference errors. I was able to compile and run it on 32 bit mingw but I need to compile and link it with 64 bit compiled binaries.
My command goes like this:
gcc -I <..fmilib\include> -L <..fmilib\lib> -lfmilib -o testfile testfile.c fmivars.c
And the following is the result that is getting printed out as a result
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x9b): undefined reference to `__imp_fmi2_import_get_real'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0xd6): undefined reference to `__imp_fmi2_import_get_integer'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x111): undefined reference to `__imp_fmi2_import_get_boolean'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x14c): undefined reference to `__imp_fmi2_import_get_string'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x187): undefined reference to `__imp_fmi2_import_set_real'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x1c2): undefined reference to `__imp_fmi2_import_set_integer'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x1fd): undefined reference to `__imp_fmi2_import_set_boolean'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x238): undefined reference to `__imp_fmi2_import_set_string'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x27a): undefined reference to `__imp_fmi2_import_new_discrete_states'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x2b6): undefined reference to `__imp_fmi2_import_collect_model_counts'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x30b): undefined reference to `__imp_fmi2_status_to_string'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x37e): undefined reference to `__imp_jm_vsnprintf'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x395): undefined reference to `__imp_fmi2_status_to_string'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x437): undefined reference to `__imp_jm_vsnprintf'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x556): undefined reference to `__imp_fmi2_import_get_version'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x575): undefined reference to `__imp_fmi2_import_get_types_platform'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x594): undefined reference to `__imp_fmi2_import_get_number_of_continuous_states'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x5a8): undefined reference to `__imp_fmi2_import_get_number_of_event_indicators'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x64a): undefined reference to `__imp_fmi2_import_instantiate'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x690): undefined reference to `__imp_fmi2_import_set_debug_logging'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x6af): undefined reference to `__imp_fmi2_status_to_string'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x6df): undefined reference to `__imp_fmi2_import_set_debug_logging'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x718): undefined reference to `__imp_fmi2_import_setup_experiment'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x733): undefined reference to `__imp_fmi2_import_enter_initialization_mode'
Is there any macro or anything set on the FMILibrary to compile with 64 bit mingw compiler on windows 64 bit? Thanks.
Assuming the library libfmilib.x.y.z provided the missing symbols then on the linker's/compiler's command line move it to the right of the .c-files requiring them
gcc -I <..fmilib\include> -L <..fmilib\lib> -o testfile testfile.c fmivars.c -lfmilib
Thank you everyone for helping me. I finally solved my problem and was able to run the code. I installed dependency walker as suggested by #PilouPili and found out that my application is looking for the library in the same folder(I don't know for some reason) and it was unable to find it. So, I copied all the static and dynamic libraries and I pasted in the folder where my testfile is. Also I changed the command line as suggested by #alk and moved the -lfmilib to the end. And I used the dynamic library instead of static one. But anyways my application runs now. Thank you so much for helping out.
This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 6 years ago.
i tried to use make on my c source code and created executable file. but the executable file did not work the intended task. even if the make file compiled and produced the executable file when i try to compile the .c file individually it gave many undefined reference problem
The errors are
/tmp/cc4tx0BG.o: In function `main':
cubist.c:(.text+0xdc): undefined reference to `Of'
cubist.c:(.text+0xe7): undefined reference to `Of'
cubist.c:(.text+0xfa): undefined reference to `Of'
cubist.c:(.text+0x10f): undefined reference to `KRInit'
cubist.c:(.text+0x114): undefined reference to `ExecTime'
cubist.c:(.text+0x127): undefined reference to `PrintHeader'
cubist.c:(.text+0x139): undefined reference to `Of'
[...]
cubist.c:(.text+0xb79): undefined reference to `MaxAtt'
cubist.c:(.text+0xb83): undefined reference to `InitialiseEnvData'
cubist.c:(.text+0xb8a): undefined reference to `XVAL'
cubist.c:(.text+0xb93): undefined reference to `CrossVal'
cubist.c:(.text+0xb9a): undefined reference to `SingleCttee'
cubist.c:(.text+0xb9f): undefined reference to `ExecTime'
cubist.c:(.text+0xbab): undefined reference to `Of'
collect2: error: ld returned 1 exit status
please, could any body tells how to use make and building executables in Linux work.
I think (not sure) that you are saying that you successfully produced an executable using Make (at least that's how I interpret "use make on my c source code and created executable file" -- do correct me if I'm wrong!). If that's the case, invoke make like this: make -B --trace, and you'll see the exact commands that were used to build the executable, and then you'll hopefully know which compiler/linker flags or libraries you missed while trying to build stuff manually.
I am trying to access png pixel data in my C code on. I found this library libpng. I downloaded latest version from this site, I am using Ubuntu 14.04. I followed the instructions in the INSTALL file. Everything went well. And then I tried to compile with gcc this piece of code. But I received this:
/tmp/ccWa9LDO.o: In function `read_png_file':
test.c:(.text+0x13c): undefined reference to `png_sig_cmp'
test.c:(.text+0x16f): undefined reference to `png_create_read_struct'
test.c:(.text+0x1a0): undefined reference to `png_create_info_struct'
test.c:(.text+0x1db): undefined reference to `png_set_longjmp_fn'
test.c:(.text+0x20c): undefined reference to `png_init_io'
test.c:(.text+0x220): undefined reference to `png_set_sig_bytes'
test.c:(.text+0x239): undefined reference to `png_read_info'
test.c:(.text+0x252): undefined reference to `png_get_image_width'
test.c:(.text+0x271): undefined reference to `png_get_image_height'
test.c:(.text+0x290): undefined reference to `png_get_color_type'
test.c:(.text+0x2af): undefined reference to `png_get_bit_depth'
test.c:(.text+0x2c4): undefined reference to `png_set_interlace_handling'
test.c:(.text+0x2e3): undefined reference to `png_read_update_info'
test.c:(.text+0x2fc): undefined reference to `png_set_longjmp_fn'
test.c:(.text+0x36f): undefined reference to `png_get_rowbytes'
test.c:(.text+0x3b2): undefined reference to `png_read_image'
/tmp/ccWa9LDO.o: In function `write_png_file':
test.c:(.text+0x430): undefined reference to `png_create_write_struct'
test.c:(.text+0x461): undefined reference to `png_create_info_struct'
test.c:(.text+0x49c): undefined reference to `png_set_longjmp_fn'
test.c:(.text+0x4cd): undefined reference to `png_init_io'
test.c:(.text+0x4e6): undefined reference to `png_set_longjmp_fn'
test.c:(.text+0x559): undefined reference to `png_set_IHDR'
test.c:(.text+0x572): undefined reference to `png_write_info'
test.c:(.text+0x58b): undefined reference to `png_set_longjmp_fn'
test.c:(.text+0x5bf): undefined reference to `png_write_image'
test.c:(.text+0x5d8): undefined reference to `png_set_longjmp_fn'
test.c:(.text+0x607): undefined reference to `png_write_end'
/tmp/ccWa9LDO.o: In function `process_file':
test.c:(.text+0x692): undefined reference to `png_get_color_type'
test.c:(.text+0x6be): undefined reference to `png_get_color_type'
test.c:(.text+0x6db): undefined reference to `png_get_color_type'
collect2: error: ld returned 1 exit status
I don't understand it because I would expect that if there is problem with installation I would get errors just for including png.h.
You said in the comments that you use gcc my_code.c, try
gcc my_code.c -lpng
The -l flag links a library, in this case libpng12-dev.
Linking means that your compiler adds the code from all the object files to create a single executable file. The object files are the separate compiled source code files (the .o files).
I don't know english very well, but I will try to help you.
I was getting this issues about 2 days, the solution is so simple, let's see.
try to do this: gcc my_code.c -lpng
afterwards you will get some file like a.out, then you need to have some picture png in same directory.
after, type this: ./a.out png_file.png res.png
The output file will be called res.png.
I think you installed only the PNG processing library. You will have to install the header files that can reference the library installed. So Install 'dev' package also like this
sudo apt-get install libpng12-dev
We are building a project that requires log4c to be linked in the static mode, the following is part of the linker error that is being generated.
/usr/local/lib/liblog4c.a(domnode-expat.o): In function `sd_domnode_read':
/log4c-1.2.1/src/sd/domnode-expat.c:316: undefined reference to `XML_ParserCreate'
/log4c-1.2.1/src/sd/domnode-expat.c:324: undefined reference to `XML_SetCommentHandler'
/log4c-1.2.1/src/sd/domnode-expat.c:325: undefined reference to `XML_SetUserData'
/log4c-1.2.1/src/sd/domnode-expat.c:327: undefined reference to `XML_Parse'
/log4c-1.2.1/src/sd/domnode-expat.c:355: undefined reference to `XML_ParserFree'
/log4c-1.2.1/src/sd/domnode-expat.c:328: undefined reference to `XML_GetErrorCode'
/log4c-1.2.1/src/sd/domnode-expat.c:328: undefined reference to `XML_ErrorString'
/usr/local/lib/liblog4c.a(domnode-expat.o): In function `sd_domnode_fread':
/log4c-1.2.1/src/sd/domnode-expat.c:242: undefined reference to `XML_ParserCreate'
/log4c-1.2.1/src/sd/domnode-expat.c:250: undefined reference to `XML_SetCommentHandler'
/log4c-1.2.1/src/sd/domnode-expat.c:251: undefined reference to `XML_SetUserData'
/log4c-1.2.1/src/sd/domnode-expat.c:258: undefined reference to `XML_GetBuffer'
/log4c-1.2.1/src/sd/domnode-expat.c:268: undefined reference to `XML_ParseBuffer'
/log4c-1.2.1/src/sd/domnode-expat.c:301: undefined reference to `XML_ParserFree'
/log4c-1.2.1/src/sd/domnode-expat.c:269: undefined reference to `XML_GetErrorCode'
/log4c-1.2.1/src/sd/domnode-expat.c:269: undefined reference to `XML_ErrorString'
collect2: ld returned 1 exit status
Off hand it seems to be missing libexpat.a, but libexpat.a is on the build machine and Eclipse is configured to find it. We have built libexpat.a with the --disable-shared parm to ./configure with no success.
Any ideas?
The solution to the static link issue is to set the linking order of the libraries to other libs
log4c
expat
pthread
This should allow log4c to link in the static mode.