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.
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 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)
I'm trying to build OpenSSL. If I build it with make (1 thread), it compiles okay. But if I build it with 3 threads (make -j3), I get LOTS of linker errors:
bntest.o: In function `message':
bntest.c:(.text+0x30): undefined reference to `BIO_puts'
bntest.c:(.text+0x3b): undefined reference to `BIO_puts'
bntest.o: In function `test_add':
bntest.c:(.text+0xe2): undefined reference to `BN_init'
bntest.c:(.text+0xec): undefined reference to `BN_init'
bntest.c:(.text+0xf6): undefined reference to `BN_init'
bntest.c:(.text+0x107): undefined reference to `BN_bntest_rand'
bntest.c:(.text+0x119): undefined reference to `BN_print'
bntest.c:(.text+0x126): undefined reference to `BIO_puts'
bntest.c:(.text+0x156): undefined reference to `BN_add'
bntest.c:(.text+0x166): undefined reference to `BN_add'
bntest.c:(.text+0x191): undefined reference to `BN_bntest_rand'
bntest.c:(.text+0x1d3): undefined reference to `BN_add'
bntest.c:(.text+0x1f5): undefined reference to `BN_print'
bntest.c:(.text+0x202): undefined reference to `BIO_puts'
bntest.c:(.text+0x20f): undefined reference to `BN_print'
bntest.c:(.text+0x21c): undefined reference to `BIO_puts'
bntest.c:(.text+0x264): undefined reference to `BN_free'
bntest.c:(.text+0x26e): undefined reference to `BN_free'
bntest.c:(.text+0x278): undefined reference to `BN_free'
bntest.o: In function `test_sub':
bntest.c:(.text+0x2af): undefined reference to `BN_init'
bntest.c:(.text+0x2b9): undefined reference to `BN_init'
bntest.c:(.text+0x2c3): undefined reference to `BN_init'
bntest.c:(.text+0x2e0): undefined reference to `BN_bntest_rand'
bntest.c:(.text+0x322): undefined reference to `BN_sub'
...and so on, for hundreds of lines...
To be clear, the exact sequence of commands I ran is:
$ wget https://www.openssl.org/source/openssl-1.0.1l.tar.gz
$ tar -xzf openssl-1.0.1l.tar.gz
$ cd openssl-1.0.1l
$ ./config
$ make -j3
I'm on Ubuntu 14.10 on an x64 machine.
This might be an RTFM-type question, but I haven't been able to see anywhere that says building OpenSSL with multiple threads is not supported.
So the question: Is building OpenSSL with multiple threads supported? If so, what am I doing wrong?
As MadScientist's comment indicates a makefile has to be designed to support parallel builds. Apparently OpenSSL is supposed to support parallel make but one of their bug reports shows that this support has on a few occasions been broken. This bug was most recently marked as fixed on December 12th, 2014, so it's possible that using a newer version of OpenSSL will fix the problem you've encountered.
Quite weird bug trying to link something to LLVMSupport :
C:/projects/builds/LLVM-3.3/lib/../lib/libLLVMsupport.a(Signals.cpp.obj):Signals.cpp:(.text+0x524): undefined reference to `__imp_SymSetOptions'
C:/projects/builds/LLVM-3.3/lib/../lib/libLLVMsupport.a(Signals.cpp.obj):Signals.cpp:(.text+0x542): undefined reference to `__imp_SymInitialize'
C:/projects/builds/LLVM-3.3/lib/../lib/libLLVMsupport.a(Signals.cpp.obj):Signals.cpp:(.text+0x576): undefined reference to `__imp_SymGetModuleBase64'
C:/projects/builds/LLVM-3.3/lib/../lib/libLLVMsupport.a(Signals.cpp.obj):Signals.cpp:(.text+0x582): undefined reference to `__imp_SymFunctionTableAccess64'
C:/projects/builds/LLVM-3.3/lib/../lib/libLLVMsupport.a(Signals.cpp.obj):Signals.cpp:(.text+0x5a1): undefined reference to `__imp_StackWalk64'
C:/projects/builds/LLVM-3.3/lib/../lib/libLLVMsupport.a(Signals.cpp.obj):Signals.cpp:(.text+0x644): undefined reference to `__imp_SymGetModuleBase64'
C:/projects/builds/LLVM-3.3/lib/../lib/libLLVMsupport.a(Signals.cpp.obj):Signals.cpp:(.text+0x6f4): undefined reference to `__imp_SymGetSymFromAddr64'
C:/projects/builds/LLVM-3.3/lib/../lib/libLLVMsupport.a(Signals.cpp.obj):Signals.cpp:(.text+0x7d9): undefined reference to `__imp_SymGetLineFromAddr64'
there are functions with similar names in dbghelp.dll
http://msdn.microsoft.com/en-us/library/windows/desktop/ms681327%28v=vs.85%29.aspx
but linking to this lib doesn't fix it.
I've been on this problem for a while... How to fix it ?
Note :
I've compiled llvm with cmake + mingw64 in 64 bits with SEH with a patch to force a correct EH method test.
Then I can't find where these symbols are used...
MinGW comes with its own implementation, just to add -limagehlp at the end (the order matters) of the command
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