here is the error when i going to make psim.
/usr/bin/ld: /tmp/ccZiibmg.o:(.bss+0x0): multiple definition of `mem_wb_state'; /tmp/ccQX7AGh.o:(.bss+0x120): first defined here
/usr/bin/ld: /tmp/ccZiibmg.o:(.bss+0x8): multiple definition of `ex_mem_state'; /tmp/ccQX7AGh.o:(.bss+0x128): first defined here
/usr/bin/ld: /tmp/ccZiibmg.o:(.bss+0x10): multiple definition of `id_ex_state'; /tmp/ccQX7AGh.o:(.bss+0x130): first defined here
/usr/bin/ld: /tmp/ccZiibmg.o:(.bss+0x18): multiple definition of `if_id_state'; /tmp/ccQX7AGh.o:(.bss+0x138): first defined here
/usr/bin/ld: /tmp/ccZiibmg.o:(.bss+0x20): multiple definition of `pc_state'; /tmp/ccQX7AGh.o:(.bss+0x140): first defined here
This is the makefile which is under the directory 'pipe'
VERSION=full
GUIMODE=-DHAS_GUI
TKLIBS=-L/usr/lib -ltk -ltcl
TKINC=-isystem /usr/include/tcl8.6
CC=gcc
CFLAGS=-Wall -O2 -DUSE_INTERP_RESULT
How to fix it?
Related
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.
I have a problem with this project (it is a minigame similar to space invaders).
Every time I try to compile it it gives me these errors:
❯ make
gcc main.o collisioni.o stampa.o gestione.o -o progetto -lncurses
/usr/bin/ld: collisioni.o:(.bss+0x0): multiple definition of `maxx'; main.o:(.bss+0x0): first defined here
/usr/bin/ld: collisioni.o:(.bss+0x4): multiple definition of `maxy'; main.o:(.bss+0x4): first defined here
/usr/bin/ld: collisioni.o:(.bss+0x8): multiple definition of `flag_navicelle'; main.o:(.bss+0x8): first defined here
/usr/bin/ld: stampa.o:(.bss+0x0): multiple definition of `maxx'; main.o:(.bss+0x0): first defined here
/usr/bin/ld: stampa.o:(.bss+0x4): multiple definition of `maxy'; main.o:(.bss+0x4): first defined here
/usr/bin/ld: stampa.o:(.bss+0x8): multiple definition of `flag_navicelle'; main.o:(.bss+0x8): first defined here
/usr/bin/ld: gestione.o:(.bss+0x0): multiple definition of `maxx'; main.o:(.bss+0x0): first defined here
/usr/bin/ld: gestione.o:(.bss+0x4): multiple definition of `maxy'; main.o:(.bss+0x4): first defined here
collect2: error: ld returned 1 exit status
make: *** [makefile:2: progetto] Errore 1
The source code of the project is this: https://github.com/Stenafo/game
I compile the code using the makefile.
I don't understand where the problem is, a friend of mine manages to compile it without errors.
This project uses processes, however I have the same problem with threads.
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.
I have just seen this post: How to tell where the symbols are defined when linking C code ; and tried to run that approach (that is, I tried to look up via -Wl,-trace-symbol=foo during the linking command) on my code, which suffers from undefined reference - but the output is not much different from what is given as an example in that post:
/usr/bin/ld: main.o: reference to foo
/usr/bin/ld: ./libfoo.a(foo.o): definition of foo
/usr/bin/ld: ./libfoo.a(foo.o): reference to fputs
/usr/bin/ld: //lib/x86_64-linux-gnu/libc.so.6: definition of fputs
The thing is, I've manually added both -L and -l specifications to my command line, which I expect should pass - but they do not.
So what I am ultimately looking for, is a way to generate a log, that tells me, say:
/usr/bin/ld: main.o: reference to foo
/usr/bin/ld: ./libyoo.a(yooA.o): symbol foo looked up, not found
/usr/bin/ld: ./libyoo.a(yooB.o): symbol foo looked up, not found
/usr/bin/ld: ./libfoo.a(foo.o): definition of foo
... which, I hope, will make me understand a bit easier, which include and linker flag directories and files end up being scanned.
Is there a way to generate a log like this?
Edit : initializing the constants of my project in a C module and declaring them in a corresponding header resolved the issue.
I am working on making a C implementation of the AES cipher (link : https://github.com/SuperTotoGo/AES_Cipher). Everything was working fine until I tried to separate my project in modules. Now when I compile I get this error :
gcc -std=c99 -g -o aes.out *.c
/usr/bin/ld: /tmp/ccpeYNuO.o:/home/pipou/AES_Cipher/aes_const.h:8: multiple definition of `AES_SUB_BOX'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:8: first defined here
/usr/bin/ld: /tmp/ccpeYNuO.o:/home/pipou/AES_Cipher/aes_const.h:28: multiple definition of `INV_AES_SUB_BOX'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:28: first defined here
/usr/bin/ld: /tmp/ccpeYNuO.o:/home/pipou/AES_Cipher/aes_const.h:48: multiple definition of `AES_LOG_TABLE'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:48: first defined here
/usr/bin/ld: /tmp/ccpeYNuO.o:/home/pipou/AES_Cipher/aes_const.h:68: multiple definition of `AES_ALOG_TABLE'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:68: first defined here
/usr/bin/ld: /tmp/ccpeYNuO.o:/home/pipou/AES_Cipher/aes_const.h:88: multiple definition of `AES_MULT_MAT'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:88: first defined here
/usr/bin/ld: /tmp/ccpeYNuO.o:/home/pipou/AES_Cipher/aes_const.h:96: multiple definition of `INV_AES_MULT_MAT'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:96: first defined here
/usr/bin/ld: /tmp/ccpeYNuO.o:/home/pipou/AES_Cipher/aes_const.h:104: multiple definition of `RCON'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:104: first defined here
/usr/bin/ld: /tmp/cczfD784.o:/home/pipou/AES_Cipher/aes_const.h:8: multiple definition of `AES_SUB_BOX'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:8: first defined here
/usr/bin/ld: /tmp/cczfD784.o:/home/pipou/AES_Cipher/aes_const.h:28: multiple definition of `INV_AES_SUB_BOX'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:28: first defined here
/usr/bin/ld: /tmp/cczfD784.o:/home/pipou/AES_Cipher/aes_const.h:48: multiple definition of `AES_LOG_TABLE'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:48: first defined here
/usr/bin/ld: /tmp/cczfD784.o:/home/pipou/AES_Cipher/aes_const.h:68: multiple definition of `AES_ALOG_TABLE'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:68: first defined here
/usr/bin/ld: /tmp/cczfD784.o:/home/pipou/AES_Cipher/aes_const.h:88: multiple definition of `AES_MULT_MAT'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:88: first defined here
/usr/bin/ld: /tmp/cczfD784.o:/home/pipou/AES_Cipher/aes_const.h:96: multiple definition of `INV_AES_MULT_MAT'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:96: first defined here
/usr/bin/ld: /tmp/cczfD784.o:/home/pipou/AES_Cipher/aes_const.h:104: multiple definition of `RCON'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:104: first defined here
/usr/bin/ld: /tmp/ccxcDlRl.o:/home/pipou/AES_Cipher/aes_const.h:8: multiple definition of `AES_SUB_BOX'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:8: first defined here
/usr/bin/ld: /tmp/ccxcDlRl.o:/home/pipou/AES_Cipher/aes_const.h:28: multiple definition of `INV_AES_SUB_BOX'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:28: first defined here
/usr/bin/ld: /tmp/ccxcDlRl.o:/home/pipou/AES_Cipher/aes_const.h:48: multiple definition of `AES_LOG_TABLE'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:48: first defined here
/usr/bin/ld: /tmp/ccxcDlRl.o:/home/pipou/AES_Cipher/aes_const.h:68: multiple definition of `AES_ALOG_TABLE'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:68: first defined here
/usr/bin/ld: /tmp/ccxcDlRl.o:/home/pipou/AES_Cipher/aes_const.h:88: multiple definition of `AES_MULT_MAT'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:88: first defined here
/usr/bin/ld: /tmp/ccxcDlRl.o:/home/pipou/AES_Cipher/aes_const.h:96: multiple definition of `INV_AES_MULT_MAT'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:96: first defined here
/usr/bin/ld: /tmp/ccxcDlRl.o:/home/pipou/AES_Cipher/aes_const.h:104: multiple definition of `RCON'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:104: first defined here
collect2: error: ld returned 1 exit status
My functions prototypes are defined in the headers and my functions are implemented in the corresponding c files, from what I understood about modular projects I normally only need to include the header files in the main file to have it working.
So, would you have any idea what I did wrong?
Also if you have any tips about making modular C projects or any advice conecerning how I have done it, please tell me!
You have several variables defined in the aes_const.h header file. As a result, each source file that is compiled has a copy of those variables. So when everything in linked, you end up with multiple definitions.
Move these variable definitions into a single source file, then put extern declarations for them in the header file.
So the header should contain:
extern const uint8_t AES_SUB_BOX[16][16];
extern const uint8_t INV_AES_SUB_BOX[16][16];
extern const uint8_t AES_LOG_TABLE[16][16];
extern const uint8_t AES_ALOG_TABLE[16][16];
extern const uint8_t AES_MULT_MAT[4][4];
extern const uint8_t INV_AES_MULT_MAT[4][4];
extern uint8_t RCON[10];
And the existing definitions should be moved to a .c file, for example aes_const.c.
The prototypes are defined in the headers, which is why the compiler detects all the names and succeeds in compilation. The failure you're getting is during link-time. That is because the linker needs the implementation of the functions, which live in the .c files.
What you need to do is to compile all the .c files and link the resulting object files together. C projects usually build all the object files first (gcc -c *.c) and then link them all together in a separate step (gcc -o aes.out *.o)