Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Multiple definitions of functions during executable generation #247

Open
samhorsfield96 opened this issue Nov 8, 2021 · 6 comments
Open

Comments

@samhorsfield96
Copy link

Hi,

I'm following the "Calling Seq from C/C++" example using the latest seq-lang release (v0.11.0) and generate a shared object, but when linking to the executable I get the following errors:

$ seqc build -o foo.o foo.seq
$ gcc -shared -L/path/to/seq/lib -o libfoo.so foo.o -no-pie -lseqrt -lomp
$ gcc -o foo -lfoo foo.c
foo.c: In function ‘int main()’:
foo.c:7:27: warning: format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 2 has type ‘int64_t {aka long int}’ [-Wformat=]
   printf("%llu\n", foo(10));
                    ~~~~~~~^
./libfoo.so: In function `_start':
(.text+0x0): multiple definition of `_start'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o:(.text+0x0): first defined here
./libfoo.so: In function `_fini':
(.fini+0x0): multiple definition of `_fini'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crti.o:(.fini+0x0): first defined here
./libfoo.so:(.rodata+0x0): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o:(.rodata.cst4+0x0): first defined here
./libfoo.so: In function `data_start':
(.data+0x0): multiple definition of `__data_start'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o:(.data+0x0): first defined here
./libfoo.so: In function `data_start':
(.data+0x8): multiple definition of `__dso_handle'
/usr/lib/gcc/x86_64-linux-gnu/7/crtbeginS.o:(.data.rel.local+0x0): first defined here
./libfoo.so: In function `_init':
(.init+0x0): multiple definition of `_init'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crti.o:(.init+0x0): first defined here
/tmp/ccre1xzA.o: In function `main':
foo.c:(.text+0x0): multiple definition of `main'
./libfoo.so:/Users/seq-lang-test/foo.seq:(.text+0x1160): first defined here
/usr/lib/gcc/x86_64-linux-gnu/7/crtendS.o:(.tm_clone_table+0x0): multiple definition of `__TMC_END__'
./libfoo.so:(.data+0x10): first defined here
/usr/bin/ld: error in ./libfoo.so(.eh_frame); no .eh_frame_hdr table will be created.
/tmp/ccre1xzA.o: In function `main':
foo.c:(.text+0xa): undefined reference to `foo(long)'
collect2: error: ld returned 1 exit status

Calling ldd on the shared object file gives me

$ ldd libfoo.so
        linux-vdso.so.1 (0x00007fffc485a000)
        libseqrt.so => /path/to/seq/lib/libseqrt.so (0x00007fc603ce0000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fc6038d0000)
        libomp.so => /path/to/seq/lib/libomp.so (0x00007fc603809000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fc603600000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fc6033f0000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fc6031d0000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fc602e20000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fc602c00000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fc604400000)

Would you be able to help with this if possible, please? I'm running this using Ubuntu 18.04 via WSL with gcc v 7.5.0 just for reference.

@markhend
Copy link
Collaborator

markhend commented Nov 8, 2021

Hi @samhorsfield96. Try changing the /path/to/seq/lib to the specific path where the Seq shared libs are installed on your system. e.g. For me it is /home/mhenders/.seq/lib/seq. You could also consider setting the LD_LIBRARY_PATH variable (see here for a brief discussion).

You may also need to try it without the -no-pie option, as shown here.

@samhorsfield96
Copy link
Author

Hi @markhend, thanks for such a speedy response. I am already linking directly to the seq lib directory (I changed it in the example just for readability). I am also already adding the seq lib directory to the LD_LIBRARY_PATH variable, and still run into the same issues.

I did try without -no-pie however I run into the below error:

/usr/bin/ld: foo.o: relocation R_X86_64_32 against `.bss' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status

@markhend
Copy link
Collaborator

markhend commented Nov 9, 2021

@samhorsfield96 I have been running the examples again and seeing the same issues as you - lots of 'multiple definition of' errors. I'm using Ubuntu (WSL) as well. Let us dig in a bit more to see if we can determine the root cause. Thank you.

@markhend
Copy link
Collaborator

markhend commented Nov 9, 2021

@samhorsfield96, I haven't determined root cause yet. I got a little closer. Perhaps this might help you.

$ seqc build -o foo.o foo.seq --relocation-model=pic
$ gcc -shared -L/home/mhenders/.seq/lib/seq -o libfoo.so foo.o -lseqrt -lomp
$ gcc -o foo -L/home/mhenders/.seq/lib/seq -lseqrt -L. -lfoo foo.c

/usr/bin/ld: /tmp/ccXc1N7d.o: in function `main':
foo.c:(.text+0xe): undefined reference to `foo'
collect2: error: ld returned 1 exit status

@samhorsfield96
Copy link
Author

@markhend unfortunately I run into the same issue as you

/tmp/ccBJNODw.o: In function `main':
foo.c:(.text+0xa): undefined reference to `foo'
collect2: error: ld returned 1 exit status

@samhorsfield96
Copy link
Author

@markhend compiling with the -c flag gets rid of the multiple definition errors, however foo is an object and not an executable

$ seqc build -o foo.o foo.seq
$ gcc -shared -L/path/to/seq/lib -o libfoo.so foo.o -no-pie -lseqrt -lomp
$ gcc -o foo -lfoo -c foo.c
$ ./foo
-bash: ./foo: cannot execute binary file: Exec format error

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants