Word Embedding Compression by Binarization (Tissier) // C-Binaries - c

For my bachelor thesis I want to apply this algorithm proposed here: Binarization by Tissier
I cloned the repository and tried to run cd near-lossless-binarization in the corrsponding directory.
However there comes up an error I don't know how to solve.
cd near-lossless-binarization && make
gcc binarize.c -o binarize -ansi -pedantic -Wall -Wextra -Wno-unused-result -Ofast -funroll-loops -lblas -lm
/usr/bin/ld: /tmp/ccxe5d0J.o: in function `apply_regularizarion_gradient':
binarize.c:(.text+0xddc): undefined reference to `cblas_sgemm'
/usr/bin/ld: binarize.c:(.text+0xf9e): undefined reference to `cblas_sgemm'
/usr/bin/ld: /tmp/ccxe5d0J.o: in function `apply_reconstruction_gradient':
binarize.c:(.text+0x1059): undefined reference to `cblas_sgemm'
/usr/bin/ld: binarize.c:(.text+0x12fb): undefined reference to `cblas_sgemm'
/usr/bin/ld: binarize.c:(.text+0x1800): undefined reference to `cblas_sgemm'
/usr/bin/ld: /tmp/ccxe5d0J.o:binarize.c:(.text+0x1e71): more undefined references to `cblas_sgemm' follow
collect2: Error: ld gab 1 as end-Status returned
Seems like there is an issue inside the corresponding file.
I already opened an issue in the repo, but need answers pretty soon..
Hoped to find anyone with C experience here who may solve my problem.
Requirements named in the repo are fulfilled.

Related

ld finds library when run stand along but cant find when building executable

I am trying to build a program that requires the linking of libndctl. However, ld fails to find the library, and the build errors out at the linking stage stating (this used to build without error some time before):
Command:
g++ tatp_db.cc tatp_nvm.cc ../include/txopt.cc -lpmem -lpthread -o tatp_nvm -std=c++11 -static
Error:
/usr/bin/ld: /usr/local/lib/libpmem.a(libpmem_all.o): in function `pmem2_device_dax_alignment':
memset_t_avx512f.c:(.text+0xb527): undefined reference to `ndctl_new'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xb59e): undefined reference to `ndctl_namespace_get_dax'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xb5b5): undefined reference to `ndctl_dax_get_align'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xb5ce): undefined reference to `ndctl_unref'
/usr/bin/ld: /usr/local/lib/libpmem.a(libpmem_all.o): in function `pmem2_device_dax_size':
memset_t_avx512f.c:(.text+0xb62f): undefined reference to `ndctl_new'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xb6a9): undefined reference to `ndctl_namespace_get_dax'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xb6c0): undefined reference to `ndctl_dax_get_size'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xb700): undefined reference to `ndctl_unref'
/usr/bin/ld: /usr/local/lib/libpmem.a(libpmem_all.o): in function `pmem2_region_namespace':
memset_t_avx512f.c:(.text+0xc3ab): undefined reference to `ndctl_bus_get_first'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xc3c0): undefined reference to `ndctl_region_get_first'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xc3d5): undefined reference to `ndctl_namespace_get_first'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xc3f2): undefined reference to `ndctl_namespace_get_dax'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xc41e): undefined reference to `ndctl_dax_get_daxctl_region'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xc463): undefined reference to `daxctl_dev_get_first'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xc475): undefined reference to `daxctl_dev_get_devname'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xc4e1): undefined reference to `daxctl_dev_get_next'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xc512): undefined reference to `ndctl_namespace_get_btt'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xc529): undefined reference to `ndctl_btt_get_block_device'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xc53b): undefined reference to `ndctl_namespace_get_pfn'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xc552): undefined reference to `ndctl_pfn_get_block_device'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xc564): undefined reference to `ndctl_namespace_get_block_device'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xc5d1): undefined reference to `ndctl_namespace_get_next'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xc5ec): undefined reference to `ndctl_region_get_next'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xc607): undefined reference to `ndctl_bus_get_next'
/usr/bin/ld: /usr/local/lib/libpmem.a(libpmem_all.o): in function `pmem2_get_region_id':
memset_t_avx512f.c:(.text+0xc64f): undefined reference to `ndctl_new'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xc6f8): undefined reference to `ndctl_region_get_id'
/usr/bin/ld: memset_t_avx512f.c:(.text+0xc70a): undefined reference to `ndctl_unref'
collect2: error: ld returned 1 exit status
make: *** [Makefile:9: all] Error 1
I tried fixing this by manually adding -lndctl to the build command
g++ tatp_db.cc tatp_nvm.cc ../include/txopt.cc -lpmem -lpthread -lndctl -o tatp_nvm -std=c++11 -static
Error:
/usr/bin/ld: cannot find -lndctl
collect2: error: ld returned 1 exit status
make: *** [Makefile:9: all] Error 1
I see that the library exists in /usr/lib/ and when running ld stand-alone (/usr/bin/ld -lndctl --verbose) it finds the library. Does anyone know what causes this to happen and a fix?
Command:
g++ tatp_db.cc tatp_nvm.cc ../include/txopt.cc -lpmem -lpthread -o tatp_nvm -std=c++11 -static
That command is wrong: you said yourself that this binary requires libndtcl, yet you aren't listing that library on the command line, so of course its symbols end up being unresolved.
I tried fixing this by manually adding -lndctl to the build command
That is the correct fix.
/usr/bin/ld: cannot find -lndctl
I see that the library exists in /usr/lib/
There are a few likely root causes:
If you are linking a 64-bit executable (which seems likely), /usr/lib/libndctl* may exist, but is a 32-bit binary.
You need a 64-bit version (usually found in /usr/lib64) and that version is not present.
You have only libndctl.so*, but not libndtcl.a (the latter is required for -static link).
To fix, you would need to install libndctl-dev or similar package.

Undefined reference. But can't find the specific library name

I'm going to assemble a program. But errors followed.
gcc -no-pie final.s -ldl -lm -lz -lrt -lpthread -lcrypt -lgmp -m64
/usr/bin/ld: error in /tmp/ccjXcZiN.o(.eh_frame); no .eh_frame_hdr table will be created.
/tmp/ccjXcZiN.o: In function `S_0x404C5A':
(.text+0x775): undefined reference to `have_libloaded'
/tmp/ccjXcZiN.o: In function `BB_73':
(.text+0x78f): undefined reference to `libhandle'
/tmp/ccjXcZiN.o: In function `BB_74':
(.text+0x79c): undefined reference to `load_library_errmsg'
/tmp/ccjXcZiN.o: In function `S_0x404CA0':
(.text+0x7bf): undefined reference to `have_libloaded'
collect2: error: ld returned 1 exit status
I know that there're some other libraries needed on the machine. But i can't search for the specific library name.

Cannot compile hackrf.c

I try to compile/build hackrf.c since i'm using the library in another code, I have hackrf.h in the same directory as the one i'm building hackrf.c in...
https://github.com/greatscottgadgets/hackrf/tree/master/host/libhackrf/src
Ideally, it should do so, but instead I get these errors in the terminal:
choza#chozaUbuntu:~/Documents/workspace_c$ gcc hackrf.c
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
/usr/bin/ld: /tmp/ccrRkrH1.o: in function `cancel_transfers':
hackrf.c:(.text+0x139): undefined reference to `libusb_cancel_transfer'
/usr/bin/ld: /tmp/ccrRkrH1.o: in function `free_transfers':
hackrf.c:(.text+0x25b): undefined reference to `libusb_free_transfer'
/usr/bin/ld: /tmp/ccrRkrH1.o: in function `allocate_transfers':
hackrf.c:(.text+0x337): undefined reference to `libusb_alloc_transfer'
/usr/bin/ld: /tmp/ccrRkrH1.o: in function `prepare_transfers':
hackrf.c:(.text+0x484): undefined reference to `libusb_submit_transfer'
/usr/bin/ld: /tmp/ccrRkrH1.o: in function `detach_kernel_drivers':
hackrf.c:(.text+0x4ee): undefined reference to `libusb_get_device'
/usr/bin/ld: hackrf.c:(.text+0x505): undefined reference to `libusb_get_active_config_descriptor'
/usr/bin/ld: hackrf.c:(.text+0x53b): undefined reference to `libusb_free_config_descriptor'
/usr/bin/ld: hackrf.c:(.text+0x555): undefined reference to `libusb_kernel_driver_active'
/usr/bin/ld: hackrf.c:(.text+0x592): undefined reference to `libusb_detach_kernel_driver'
And so on...
Then I suppose I should directly link libusb...
But I get this:
choza#chozaUbuntu:~/Documents/workspace_c$ gcc hackrf.c -lusb-1.0
/usr/bin/ld: /tmp/ccfIzbqD.o: undefined reference to symbol 'pthread_join##GLIBC_2.2.5'
/usr/bin/ld: /lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
And pthread...
choza#chozaUbuntu:~/Documents/workspace_c$ gcc hackrf.c -lusb-1.0 -pthread
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
collect2: error: ld returned 1 exit status
I really don't know how to fix the error above or how to successfully compile the .c file anymore.
I'm using VS Code in Ubuntu 20.04.
What should I do?
I really don't know how to fix the error above or how to successfully compile the .c file anymore.
You aren't having a problem compiling, you are having a problem linking.
The reason your link fails is that hackrf.c lacks main() function, which every C program requires. And that's because it's part of a library.
Generally you'll want to build the entire project, not just a library, using the instructions the project provides.
If you do want to build a library, then you should link it with the rest of your program.

understanding compilation commands C and configuring CodeBlocks

I'm learning C in college. And I wanted to try new things, so I decided to use the allegro Game library to create some stuff. I followed the tutorial, and everything went fine. I wrote a piece of code in the text editor and executed the commands provided by the tutorial and it compiled and run. (I'm on linux btw).
These are the commands:
gcc hello.c -o hello $(pkg-config allegro-5 allegro_font-5 --libs --cflags)
./hello
So, I understand that gcc is calling the gcc compiler and hello.c is the name of the source code file and -o hello specifies the name of the compiled file. but the next part is ambiguous and beyond my knowledge:
$(pkg-config allegro-5 allegro_font-5 --libs --cflags)
So can anyone explain what it means (it has something to do with linking). and if I remove that part the compiler returns these error codes:
/usr/bin/ld: /tmp/ccIQsEis.o: in function `main':
hello.c:(.text+0x2f): undefined reference to `al_install_system'
/usr/bin/ld: hello.c:(.text+0x34): undefined reference to `al_install_keyboard'
/usr/bin/ld: hello.c:(.text+0x45): undefined reference to `al_create_timer'
/usr/bin/ld: hello.c:(.text+0x4e): undefined reference to `al_create_event_queue'
/usr/bin/ld: hello.c:(.text+0x61): undefined reference to `al_create_display'
/usr/bin/ld: hello.c:(.text+0x6a): undefined reference to `al_create_builtin_font'
/usr/bin/ld: hello.c:(.text+0x73): undefined reference to `al_get_keyboard_event_source'
/usr/bin/ld: hello.c:(.text+0x85): undefined reference to `al_register_event_source'
/usr/bin/ld: hello.c:(.text+0x91): undefined reference to `al_get_display_event_source'
/usr/bin/ld: hello.c:(.text+0xa3): undefined reference to `al_register_event_source'
/usr/bin/ld: hello.c:(.text+0xaf): undefined reference to `al_get_timer_event_source'
/usr/bin/ld: hello.c:(.text+0xc1): undefined reference to `al_register_event_source'
/usr/bin/ld: hello.c:(.text+0xd4): undefined reference to `al_start_timer'
/usr/bin/ld: hello.c:(.text+0xe7): undefined reference to `al_wait_for_event'
/usr/bin/ld: hello.c:(.text+0x125): undefined reference to `al_is_event_queue_empty'
/usr/bin/ld: hello.c:(.text+0x13d): undefined reference to `al_map_rgb'
/usr/bin/ld: hello.c:(.text+0x16a): undefined reference to `al_clear_to_color'
/usr/bin/ld: hello.c:(.text+0x17e): undefined reference to `al_map_rgb'
/usr/bin/ld: hello.c:(.text+0x1ca): undefined reference to `al_draw_text'
/usr/bin/ld: hello.c:(.text+0x1cf): undefined reference to `al_flip_display'
/usr/bin/ld: hello.c:(.text+0x1e7): undefined reference to `al_destroy_font'
/usr/bin/ld: hello.c:(.text+0x1f3): undefined reference to `al_destroy_display'
/usr/bin/ld: hello.c:(.text+0x1ff): undefined reference to `al_destroy_timer'
/usr/bin/ld: hello.c:(.text+0x20b): undefined reference to `al_destroy_event_queue'
collect2: error: ld returned 1 exit status
And for the second part of the question, I tried to compile this code in code:blocks but it returns the same errors given by the compiler without the term: $(pkg-config allegro-5 allegro_font-5 --libs --cflags)
So, what configuration should I change in codeblocks so that it compiles well code using allegro libraries.
PS. I didn't include the source code intentionally as it adds no useful information to the question, only clutters it.
This is a Bash command-syntax feature which executes another command and then provides its output as a string. This idiom is being used here to programmatically provide command-line parameters to the gcc command. The pkg-config command is being executed, and it returns a string which becomes part of – is textually included in – the command-string for invoking gcc. (Which of course neither knows nor cares where its command-line parameters "come from.")
(Clever, huh?)
For example, try this:
echo $(ls)
You will be rewarded with a list of all the files in the current directory, concatenated as a string.
To elaborate on the answer by #Mike Robinson,
$(pkg-config allegro-5 allegro_font-5 --libs --cflags) will execute the command pkg-config and substitute the result. pkg-config is build utility that helps when compiling C programs. It's not specific to allegro, it is used by many C libraries.
In this particular case, pkg-config is called with the parameters allegro-5 allegro_font-5 --libs --cflags, which asks pkg-config "what are the compiler options (--cflags) and libraries (--libs) I need when compiling and linking with allegro?" Allegro consists of several modules, in this case you chose the main module 'allegro' and the font module 'allegro_font'. In both cases you're referring to major version 5 of allegro.
On your system, the result of the command is -I/usr/include/x86_64-linux-gnu -lallegro_font -lallegro. The meaning of these options is as follows:
-I/usr/include/x86_64-linux-gnu tells the compiler to add the path /usr/include/x86_64-linux-gnu to the header search path (because the allegro headers are located there)
-lallegro_font and '-lallegro` tells the linker to add the allegro_font and allegro libraries respectively. That also explains why you get all those undefined reference errors when you remove this - you are no longer telling the linker to add the allegro library, so it can't find all those functions anymore.

libmodbus: how to compile application including libmodbus library?

I have a problem with compilation of my application, which is based on libmodbus library:
https://github.com/stephane/libmodbus
I have tried to compile it using this command:
cc pkg-config --cflags --libs libmodbus modbus.c -o modbus
But I get the following errors:
/usr/bin/ld: /tmp/cckdtbWy.o: in function `main':
modbus.c:(.text+0x1b): undefined reference to `modbus_new_tcp_pi'
/usr/bin/ld: modbus.c:(.text+0x5c): undefined reference to `modbus_connect'
/usr/bin/ld: modbus.c:(.text+0x8d): undefined reference to `modbus_free'
/usr/bin/ld: modbus.c:(.text+0xa3): undefined reference to `modbus_connect'
/usr/bin/ld: modbus.c:(.text+0xde): undefined reference to `modbus_read_bits'
/usr/bin/ld: modbus.c:(.text+0x11e): undefined reference to `modbus_close'
/usr/bin/ld: modbus.c:(.text+0x12a): undefined reference to `modbus_free'
collect2: error: ld returned 1 exit status
I would appreciate any help!
Best regards!
I have worked through this problem and my solution is that:
1. Create modbus.conf file in /etc/ld.so.conf.d/.
2. Run sudo ldconfig.
3. Compile your application/program with the following command:
gcc <name>.c -o <name> -I/usr/local/include/modbus/ -lmodbus
It has worked for me, but I am not sure whether the first step is necessary.
Did you install the libmodbus-dev? You should try this: sudo apt-get install -y libmodbus-dev.
See v3.1.6 and v3.0.8: libmodbus docs

Resources