Thread: I can't spot my mistake...

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,735
    Quote Originally Posted by Hodor View Post
    Still won't build for me

    Code:
    $ make --version
    GNU Make 4.2.1
    $ gcc --version
    gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0
    
    $ make debug run
    .
    .
    Finished checking
    PRJ_DST_BIN=alu_d.AppImage
    PRJ_DST_LIB=libalu_d.so
    cc -ggdb -D _DEBUG -fPIC -shared -Wall -Wextra -I cloned/fbstdc/include  -o test_d.o -c test.c
    cc -ggdb -D _DEBUG -fPIC -shared -Wall -Wextra -I cloned/fbstdc/include  -o alu_vec_d.o -c alu_vec.c
    cc -ggdb -D _DEBUG -fPIC -shared -Wall -Wextra -I cloned/fbstdc/include  -o alu_mem_d.o -c alu_mem.c
    cc -ggdb -D _DEBUG -fPIC -shared -Wall -Wextra -I cloned/fbstdc/include  -o alu_bit_d.o -c alu_bit.c
    cc -ggdb -D _DEBUG -fPIC -shared -Wall -Wextra -I cloned/fbstdc/include  -o alu_math_d.o -c alu_math.c
    cc -ggdb -D _DEBUG -fPIC -shared -Wall -Wextra -I cloned/fbstdc/include  -o alu_int_d.o -c alu_int.c
    cc -ggdb -D _DEBUG -fPIC -shared -Wall -Wextra -I cloned/fbstdc/include  -o alu_main_d.o -c alu_main.c
    cc -ggdb -D _DEBUG -fPIC -shared -Wall -Wextra -I cloned/fbstdc/include  -o alu_uint_d.o -c alu_uint.c
    cc -ggdb -D _DEBUG -fPIC -shared  -o libalu_d.so alu_vec_d.o alu_mem_d.o alu_bit_d.o alu_math_d.o alu_int_d.o alu_main_d.o alu_uint_d.o -Wl,-rpath=./
    cc -ggdb -D _DEBUG -fPIE -L . -l alu_d  -o alu_d.AppImage test_d.o -Wl,-rpath=./
    /usr/bin/ld: test_d.o: in function `uint_compare':
    /home/hodor/tmp/alu/test.c:39: undefined reference to `alu_uint_cmp'
    /usr/bin/ld: test_d.o: in function `int_compare':
    /home/hodor/tmp/alu/test.c:84: undefined reference to `alu_int_cmp'
    /usr/bin/ld: test_d.o: in function `reg_compare':
    /home/hodor/tmp/alu/test.c:113: undefined reference to `alu_get_regv'
    .
    .
    /home/hodor/tmp/alu/test.c:1368: undefined reference to `alu_setup_reg'
    /usr/bin/ld: /home/hodor/tmp/alu/test.c:1388: undefined reference to `alu_vec'
    /usr/bin/ld: /home/hodor/tmp/alu/test.c:1389: undefined reference to `alu_vec'
    collect2: error: ld returned 1 exit status
    make[1]: *** [main.mak:89: alu_d.AppImage] Error 1
    make: *** [1st.mak:6: debug] Error 2
    You probably have old objects there, add rebuild to the target list then do normally, I haven't figured out why make is not rebuilding objects as it ought to, feel free to investigate that later, not my primary concern at the moment

  2. #2
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Quote Originally Posted by awsdert View Post
    You probably have old objects there, add rebuild to the target list then do normally, I haven't figured out why make is not rebuilding objects as it ought to, feel free to investigate that later, not my primary concern at the moment
    Unfortunately not (I did make clean first). But, just to make sure I deleted the directory and re-cloned your repo... exactly the same result as above

  3. #3
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,735
    Quote Originally Posted by Hodor View Post
    Unfortunately not (I did make clean first). But, just to make sure I deleted the directory and re-cloned your repo... exactly the same result as above
    That's weird, the 1st 2 are defined right at the top of their relative files (alu_uint.c & alu_int.c), the 3rd is in alu_main.c right under alu_get_reg()... AH! Check if libalu_d.so still exists in your directory, it may have been 'cleaned' somehow

  4. #4
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Quote Originally Posted by awsdert View Post
    That's weird, the 1st 2 are defined right at the top of their relative files (alu_uint.c & alu_int.c), the 3rd is in alu_main.c right under alu_get_reg()... AH! Check if libalu_d.so still exists in your directory, it may have been 'cleaned' somehow
    Yeah it built libalu_d.so ok (it's in the directory); it's not linking though

    Code:
    $ ls
    1st.mak      alu.h        alu_int_d.o   alu_math_d.o  alu_uint_d.o  cloned       libalu_d.so  test_d.o
    GNUmakefile  alu_bit.c    alu_main.c    alu_mem.c     alu_vec.c     dst_cc.mak   main.mak
    LICENSE      alu_bit_d.o  alu_main_d.o  alu_mem_d.o   alu_vec_d.o   dst_sys.mak  makefile
    README.md    alu_int.c    alu_math.c    alu_uint.c    char.mak      func.mak     test.c

  5. #5
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,735
    Quote Originally Posted by Hodor View Post
    Yeah it built libalu_d.so ok (it's in the directory); it's not linking though

    Code:
    $ ls
    1st.mak      alu.h        alu_int_d.o   alu_math_d.o  alu_uint_d.o  cloned       libalu_d.so  test_d.o
    GNUmakefile  alu_bit.c    alu_main.c    alu_mem.c     alu_vec.c     dst_cc.mak   main.mak
    LICENSE      alu_bit_d.o  alu_main_d.o  alu_mem_d.o   alu_vec_d.o   dst_sys.mak  makefile
    README.md    alu_int.c    alu_math.c    alu_uint.c    char.mak      func.mak     test.c
    Strange, I honestly suck at makefiles (despite using them in every project) so I don't know what to do about that, as far as I can see gcc should find it without issue as the directory itself is included via the '-L .' and the library should've been correctly referenced via '-l alu_d', if you got any ideas just give it a try, let me know if something causes it to link, I'll incorporate it into mine and upload it

  6. #6
    Registered User
    Join Date
    Sep 2020
    Posts
    425
    Hi,

    I did clone your repo, and tried building it with just "make" and had no success:

    Code:
    ....
    test.c:(.text+0x4529): undefined reference to `alu_str2int'
    test.c:(.text+0x45c7): undefined reference to `alu_int2str'
    test.c:(.text+0x46a3): undefined reference to `alu_rem_reg_node'
    test.o: In function `print_value':
    test.c:(.text+0x48d4): undefined reference to `alu_block'
    test.c:(.text+0x4c22): undefined reference to `alu_block'
    test.c:(.text+0x4d78): undefined reference to `alu_block'
    test.o: In function `main':
    test.c:(.text+0x4e55): undefined reference to `alu_setup_reg'
    test.c:(.text+0x4ffc): undefined reference to `alu_vec'
    collect2: error: ld returned 1 exit status
    main.mak:91: recipe for target 'alu.AppImage' failed
    make[3]: *** [alu.AppImage] Error 1
    1st.mak:6: recipe for target 'build' failed
    make[2]: *** [build] Error 2
    main.mak:68: recipe for target 'all' failed
    make[1]: *** [all] Error 2
    1st.mak:6: recipe for target 'all' failed
    make: *** [all] Error 2
    So I short-cut it all:

    Code:
    ~/alu$ gcc -o alu *.c -I cloned/fbstdc/include
    ~/alu$
    I now also get your issue:

    Code:
    :~/alu$ ./alu
    test.c:1341: main() Pre-allocating 32 ALU registers...
    test.c:698: compare() 'Comparing values...'
    test.c:699: compare() '==========================================='
    *** stack smashing detected ***: <unknown> terminated
    Aborted (core dumped)
    So now I compiled with warnings turned up to 11:

    Code:
    gcc -o alu *.c -I cloned/fbstdc/include -Wall -pedantic -O4
    I get 556 lines of warning where dodgy stuff is going on. You really want to fix all of thoses before you start any serious debugging.

    But seriously: I'm more then willing to help you get this into shape, but do you really want my help?

    I do know a bit of this stuff - if you want, have a look at my toy RISCV RV32I CPU's ALU.

    Rudi-RV32I/alu.vhd at master * hamsternz/Rudi-RV32I * GitHub
    Last edited by hamster_nz; 09-15-2020 at 04:15 PM.

  7. #7
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,735
    Quote Originally Posted by hamster_nz View Post
    Hi,

    I did clone your repo, and tried building it with just "make" and had no success:

    Code:
    ....
    test.c:(.text+0x4529): undefined reference to `alu_str2int'
    test.c:(.text+0x45c7): undefined reference to `alu_int2str'
    test.c:(.text+0x46a3): undefined reference to `alu_rem_reg_node'
    test.o: In function `print_value':
    test.c:(.text+0x48d4): undefined reference to `alu_block'
    test.c:(.text+0x4c22): undefined reference to `alu_block'
    test.c:(.text+0x4d78): undefined reference to `alu_block'
    test.o: In function `main':
    test.c:(.text+0x4e55): undefined reference to `alu_setup_reg'
    test.c:(.text+0x4ffc): undefined reference to `alu_vec'
    collect2: error: ld returned 1 exit status
    main.mak:91: recipe for target 'alu.AppImage' failed
    make[3]: *** [alu.AppImage] Error 1
    1st.mak:6: recipe for target 'build' failed
    make[2]: *** [build] Error 2
    main.mak:68: recipe for target 'all' failed
    make[1]: *** [all] Error 2
    1st.mak:6: recipe for target 'all' failed
    make: *** [all] Error 2
    So I short-cut it all:

    Code:
    ~/alu$ gcc -o alu *.c -I cloned/fbstdc/include
    ~/alu$
    I now also get your issue:

    Code:
    :~/alu$ ./alu
    test.c:1341: main() Pre-allocating 32 ALU registers...
    test.c:698: compare() 'Comparing values...'
    test.c:699: compare() '==========================================='
    *** stack smashing detected ***: <unknown> terminated
    Aborted (core dumped)
    So now I compiled with warnings turned up to 11:

    Code:
    gcc -o alu *.c -I cloned/fbstdc/include -Wall -pedantic -O4
    I get 556 lines of warning where dodgy stuff is going on. You really want to fix all of thoses before you start any serious debugging.

    But seriously: I'm more then willing to help you get this into shape, but do you really want my help?

    I do know a bit of this stuff - if you want, have a look at my toy RISCV RV32I CPU's ALU.

    Rudi-RV32I/alu.vhd at master * hamsternz/Rudi-RV32I * GitHub
    I actually forgot that flag existed, considering the type of project it is there's no real reason for me to not add it in and leave it there permanently, already helping me identify a bunch of bugs introduced while I was changing the core API, dealing with them now, some on the other hand are minor and safe to ignore (fixing 'em anyways though)

  8. #8
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,735
    Quote Originally Posted by Hodor View Post
    Yeah it built libalu_d.so ok (it's in the directory); it's not linking though

    Code:
    $ ls
    1st.mak      alu.h        alu_int_d.o   alu_math_d.o  alu_uint_d.o  cloned       libalu_d.so  test_d.o
    GNUmakefile  alu_bit.c    alu_main.c    alu_mem.c     alu_vec.c     dst_cc.mak   main.mak
    LICENSE      alu_bit_d.o  alu_main_d.o  alu_mem_d.o   alu_vec_d.o   dst_sys.mak  makefile
    README.md    alu_int.c    alu_math.c    alu_uint.c    char.mak      func.mak     test.c
    AH! Just a thought, try removing the 'lib' part from the library name, maybe your system doesn't prepend that when searching

  9. #9
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,735
    Well I tried adding the profiling as a target/goal, as you might have guessed I didn't succeed:
    Code:
    make profile run
    MAKECMDGOALS=profile run
    make -j 1 --no-print-directory -f main.mak profile run
    PRJ_SRC_FILES = 'test.c alu_bit.c alu_int.c alu_main.c alu_math.c alu_mem.c alu_uint.c alu_vec.c'
    Checking 3rd Party libraries are upto date
    cd 'cloned/fbstdc' && git config pull.rebase true && git pull
    Already up to date.
    Finished checking
    PRJ_DST_BIN=alu_p.AppImage
    PRJ_DST_LIB=libalu_p.so
    make[1]: Nothing to be done for 'profile'.
    gprof ./alu_p.AppImage
    gmon.out: No such file or directory
    make[1]: *** [main.mak:83: run] Error 1
    make: *** [1st.mak:6: profile] Error 2
    Compilation failed.
    Any ideas why it failed?

  10. #10
    Registered User
    Join Date
    Sep 2020
    Posts
    425
    Quote Originally Posted by awsdert View Post
    Well I tried adding the profiling as a target/goal, as you might have guessed I didn't succeed:
    Code:
    make profile run
    MAKECMDGOALS=profile run
    make -j 1 --no-print-directory -f main.mak profile run
    PRJ_SRC_FILES = 'test.c alu_bit.c alu_int.c alu_main.c alu_math.c alu_mem.c alu_uint.c alu_vec.c'
    Checking 3rd Party libraries are upto date
    cd 'cloned/fbstdc' && git config pull.rebase true && git pull
    Already up to date.
    Finished checking
    PRJ_DST_BIN=alu_p.AppImage
    PRJ_DST_LIB=libalu_p.so
    make[1]: Nothing to be done for 'profile'.
    gprof ./alu_p.AppImage
    gmon.out: No such file or directory
    make[1]: *** [main.mak:83: run] Error 1
    make: *** [1st.mak:6: profile] Error 2
    Compilation failed.
    Any ideas why it failed?
    Can't see it compiling any of the -c- source with "-pg" in that output.

  11. #11
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,735
    Quote Originally Posted by hamster_nz View Post
    Can't see it compiling any of the -c- source with "-pg" in that output.
    That was because I had done a rebuildall prior to that however looking at another rebuild I noticed that I failed to actually add the variable holding the flags, having done that the output now looks like this:
    Code:
    make profile run
    MAKECMDGOALS=profile run
    make -j 1 --no-print-directory -f main.mak profile run
    PRJ_SRC_FILES = 'test.c alu_bit.c alu_int.c alu_main.c alu_math.c alu_mem.c alu_uint.c alu_vec.c'
    Checking 3rd Party libraries are upto date
    cd 'cloned/fbstdc' && git config pull.rebase true && git pull
    Already up to date.
    Finished checking
    PRJ_DST_BIN=alu_p.AppImage
    PRJ_DST_LIB=libalu_p.so
    cc -D NDEBUG -pg -fPIC -Wall -Wextra -pedantic -I cloned/fbstdc/include  -o test_p.o -c test.c
    cc -D NDEBUG -pg -fPIC -Wall -Wextra -pedantic -I cloned/fbstdc/include  -o alu_bit_p.o -c alu_bit.c
    cc -D NDEBUG -pg -fPIC -Wall -Wextra -pedantic -I cloned/fbstdc/include  -o alu_int_p.o -c alu_int.c
    cc -D NDEBUG -pg -fPIC -Wall -Wextra -pedantic -I cloned/fbstdc/include  -o alu_main_p.o -c alu_main.c
    cc -D NDEBUG -pg -fPIC -Wall -Wextra -pedantic -I cloned/fbstdc/include  -o alu_math_p.o -c alu_math.c
    cc -D NDEBUG -pg -fPIC -Wall -Wextra -pedantic -I cloned/fbstdc/include  -o alu_mem_p.o -c alu_mem.c
    cc -D NDEBUG -pg -fPIC -Wall -Wextra -pedantic -I cloned/fbstdc/include  -o alu_uint_p.o -c alu_uint.c
    cc -D NDEBUG -pg -fPIC -Wall -Wextra -pedantic -I cloned/fbstdc/include  -o alu_vec_p.o -c alu_vec.c
    cc -D NDEBUG -pg -fPIC -shared  -o libalu_p.so alu_bit_p.o alu_int_p.o alu_main_p.o alu_math_p.o alu_mem_p.o alu_uint_p.o alu_vec_p.o -Wl,-rpath=./
    cc -D NDEBUG -pg -fPIE -L .  -o alu_p.AppImage test_p.o -Wl,-rpath=./ -l alu_p
    gprof ./alu_p.AppImage
    gmon.out: No such file or directory
    make[1]: *** [main.mak:83: run] Error 1
    make: *** [1st.mak:6: profile] Error 2
    Compilation failed.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can anyone help to spot mistake in the code
    By chess_queen in forum C Programming
    Replies: 1
    Last Post: 10-21-2012, 10:37 AM
  2. Can you spot my mistake?
    By Brewer in forum C Programming
    Replies: 13
    Last Post: 11-12-2006, 12:50 PM
  3. going to a certain spot in a file...
    By agerealm in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2002, 02:31 AM

Tags for this Thread