Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import of ".h" file for extern functions results in duplicate definitions #628

Open
GWRon opened this issue Jul 6, 2023 · 2 comments
Open

Comments

@GWRon
Copy link
Contributor

GWRon commented Jul 6, 2023

When importing a file which imports an ".h" file to define external function, this results in duplicate definitions:
test.bmx

SuperStrict
Framework brl.standardio

Import "ext.bmx"

print test()
print "Done."

ext.bmx:

SuperStrict 
Import "external.h"

Extern 
	Function test:Int() = "int test()"
EndExtern

external.h:

#include <stddef.h>
#ifndef EXTERNAL_H
#define EXTERNAL_H

int test() { return 1; }
#endif

outputs:

./bmk makeapp -g x64 -t console -a -r -x "/bmx_tests/imports/test.bmx" (in directory: /BlitzMaxNG/bin)
[  9%] Processing:ext.bmx
[ 10%] Processing:test.bmx
[ 90%] Compiling:ext.bmx.release.linux.x64.c
[ 91%] Compiling:test.bmx.console.release.linux.x64.c
[100%] Linking:test
/usr/bin/ld: /bmx_tests/imports/.bmx/ext.bmx.release.linux.x64.o: in function `test':
ext.bmx.release.linux.x64.c:(.text+0x0): multiple definition of `test'; /bmx_tests/imports/.bmx/test.bmx.console.release.linux.x64.o:test.bmx.console.release.linux.x64.c:(.text+0x0): first defined here
collect2: error: ld returned 1 exit status
Compilation failed.
Build Error: Failed to link /bmx tests/imports/test

Renaming the external to "external.c" (and importing this instead) results in

1
Done.

Only "visible" difference I saw is when doing that import "external.h": this leads to gcc "-I"-ing the project folder

[ 10%] Processing:test.bmx
Tools/BlitzMaxNG/bin/bcc  -g x64 -v -r -h -s -w -f brl.standardio -t gui -p linux -o Projekte/Testcodes/bmx_tests/imports/.bmx/test.bmx.gui.release.linux.x64.s Projekte/Testcodes/bmx_tests/imports/test.bmx
Parsing...
Semanting...
Generating interface...
Generating header...
Generating source...
[ 90%] Compiling:ext.bmx.release.linux.x64.c
gcc -ITools/BlitzMaxNG/mod -ITools/BlitzMaxNG/mod/brl.mod/blitz.mod -ITools/BlitzMaxNG/mod/brl.mod/appstub.mod -ITools/BlitzMaxNG/mod/brl.mod/standardio.mod -IProjekte/Testcodes/bmx_tests/imports  -DNDEBUG  -w -DBMX_NG -fno-strict-aliasing -fpie -fno-exceptions -c -O3 -msse3 -s  -o Projekte/Testcodes/bmx_tests/imports/.bmx/ext.bmx.release.linux.x64.o Projekte/Testcodes/bmx_tests/imports/.bmx/ext.bmx.release.linux.x64.c
[ 91%] Compiling:test.bmx.gui.release.linux.x64.c
gcc -ITools/BlitzMaxNG/mod -ITools/BlitzMaxNG/mod/brl.mod/blitz.mod -ITools/BlitzMaxNG/mod/brl.mod/appstub.mod -ITools/BlitzMaxNG/mod/brl.mod/standardio.mod  -DNDEBUG  -w -DBMX_NG -fno-strict-aliasing -fpie -fno-exceptions -c -O3 -msse3 -s  -o Projekte/Testcodes/bmx_tests/imports/.bmx/test.bmx.gui.release.linux.x64.o Projekte/Testcodes/bmx_tests/imports/.bmx/test.bmx.gui.release.linux.x64.c
[100%] Linking:test
g++ -m64 -no-pie -fpie -pthread -o Projekte/Testcodes/bmx_tests/imports/test Tools/BlitzMaxNG/tmp/ld.tmp -L/usr/X11R6/lib -L/usr/lib
/usr/bin/ld: Projekte/Testcodes/bmx_tests/imports/.bmx/ext.bmx.release.linux.x64.o: in function `test':
ext.bmx.release.linux.x64.c:(.text+0x0): multiple definition of `test'; Projekte/Testcodes/bmx_tests/imports/.bmx/test.bmx.gui.release.linux.x64.o:test.bmx.gui.release.linux.x64.c:(.text+0x0): first defined here
collect2: error: ld returned 1 exit status
Build Error: Failed to link Projekte/Testcodes/bmx_tests/imports/test
Process complete
@woollybah
Copy link
Member

woollybah commented Jul 6, 2023

You don't need to import a header.

You can just do this

SuperStrict 

Extern 
	Function test:Int()
EndExtern

I see what you are trying to do.
We don't support header only imports like that.

You'll need to create a .c file or something, and include your header there.

@woollybah
Copy link
Member

We can update the "Interfacing with C" section of the docs to note that you can't import headers in this way and expect to use them like that.

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

No branches or pull requests

2 participants