Jump to page: 1 24  
Page
Thread overview
Cannot compile betterC app in windows using stderr
Feb 02, 2022
Abby
Feb 02, 2022
forkit
Feb 02, 2022
Abby
Feb 02, 2022
forkit
Feb 02, 2022
Basile B.
Feb 02, 2022
Basile B.
Feb 02, 2022
forkit
Feb 02, 2022
duser
Feb 02, 2022
forkit
Feb 02, 2022
bauss
Feb 02, 2022
Tejas
Feb 02, 2022
kinke
Feb 02, 2022
Abby
Feb 02, 2022
Dennis
Feb 02, 2022
forkit
Feb 02, 2022
forkit
Feb 02, 2022
forkit
Feb 02, 2022
Walter Bright
Feb 03, 2022
kinke
Feb 03, 2022
kinke
Feb 04, 2022
Tejas
Feb 04, 2022
Walter Bright
February 02, 2022

I have a simple

dub.sdl

name "test"
targetType "executable"
buildOptions "betterC"

app.d

module test;
import core.stdc.stdio : fprintf, stderr;

extern(C) int main(string[] args)
{
	fprintf(stderr, "Test\n",);
	return 0;
}

When I'm trying to compile this on windows with latest dmd or ldc I get

test ~master: building configuration "application"...
Linking...
test.obj : error LNK2019: unresolved external symbol stderr referenced in function main
.dub\build\application-debug-windows-x86_64-dmd_v2.098.1-dirty-FB5231E74956BBA34BF960F450A8342C\test.exe : fatal error LNK1120: 1 unresolved externals
Error: linker exited with status 1120
C:\D\dmd2\windows\bin64\dmd.exe failed with exit code 1.

Works with dmd-2.091.0

Any idea what might be the problem here?

February 02, 2022
On Wednesday, 2 February 2022 at 01:24:30 UTC, Abby wrote:
>


a link error with the 64bit version of dmd ??

try: -m32
February 02, 2022

On Wednesday, 2 February 2022 at 03:34:29 UTC, forkit wrote:

>

On Wednesday, 2 February 2022 at 01:24:30 UTC, Abby wrote:

>

a link error with the 64bit version of dmd ??

try: -m32

Hi did not help

dub build --arch=x86_64

## Warning for package test ##

The following compiler flags have been specified in the package description
file. They are handled by DUB and direct use in packages is discouraged.
Alternatively, you can set the DFLAGS environment variable to pass custom flags
to the compiler, or use one of the suggestions below:

-m32: Use --arch=x86/--arch=x86_64/--arch=x86_mscoff to specify the target architecture, e.g. 'dub build --arch=x86_64'

Performing "debug" build using C:\D\dmd2\windows\bin64\dmd.exe for x86_64.
test ~master: building configuration "application"...
Linking...
test.obj : error LNK2019: unresolved external symbol stderr referenced in function main
.dub\build\application-debug-windows-x86_64-dmd_v2.098.1-dirty-ED981EB8716B85E9E2580186FAF4E89B\test.exe : fatal error LNK1120: 1 unresolved externals
Error: linker exited with status 1120
C:\D\dmd2\windows\bin64\dmd.exe failed with exit code 1.
February 02, 2022
On Wednesday, 2 February 2022 at 06:20:39 UTC, Abby wrote:
>

I don't know about dub. never used it.

I can say, that your code will compile and run fine if compiled with dmd using:

dmd -m32 -betterC mycode.d

but not

dmd -m64 -betterC mycode.d

it seems like a MSVC linking error (possibly unresolved references or something).

Also, this is a Windows issue. The same code will compile fine on linux -32 or -m64

Someone with more expertise will need to troubleshoot this further ;-)
February 02, 2022

On Wednesday, 2 February 2022 at 01:24:30 UTC, Abby wrote:

>

I have a simple

dub.sdl

name "test"
targetType "executable"
buildOptions "betterC"

app.d

module test;
import core.stdc.stdio : fprintf, stderr;

extern(C) int main(string[] args)
{
	fprintf(stderr, "Test\n",);
	return 0;
}

When I'm trying to compile this on windows with latest dmd or ldc I get

test ~master: building configuration "application"...
Linking...
test.obj : error LNK2019: unresolved external symbol stderr referenced in function main
.dub\build\application-debug-windows-x86_64-dmd_v2.098.1-dirty-FB5231E74956BBA34BF960F450A8342C\test.exe : fatal error LNK1120: 1 unresolved externals
Error: linker exited with status 1120
C:\D\dmd2\windows\bin64\dmd.exe failed with exit code 1.

Works with dmd-2.091.0

Any idea what might be the problem here?

Yes, I have an idea, although not a Windows user. So look at the definitions i core.stdc.stdio:

else version (CRuntime_Microsoft)
{
    ///
    shared FILE* stdin;  // = &__iob_func()[0];
    ///
    shared FILE* stdout; // = &__iob_func()[1];
    ///
    shared FILE* stderr; // = &__iob_func()[2];
}

shouldn't these variable declarations be extern ?

February 02, 2022

On Wednesday, 2 February 2022 at 07:33:58 UTC, Basile B. wrote:

>

On Wednesday, 2 February 2022 at 01:24:30 UTC, Abby wrote:

>

I have a simple

dub.sdl

name "test"
targetType "executable"
buildOptions "betterC"

shouldn't these variable declarations be extern ?

Try

module test;
import core.stdc.stdio : FILE, fprintf;

extern shared FILE* stderr;

extern(C) int main(string[] args)
{
	fprintf(stderr, "Test\n",);
	return 0;
}

to confirm if it is or not the extern problem

February 02, 2022
On Wednesday, 2 February 2022 at 07:51:07 UTC, Basile B. wrote:
>
> extern shared FILE* stderr;

nope. won't even compile with -m32 now
February 02, 2022

On Wednesday, 2 February 2022 at 07:51:07 UTC, Basile B. wrote:

>

On Wednesday, 2 February 2022 at 07:33:58 UTC, Basile B. wrote:

>

On Wednesday, 2 February 2022 at 01:24:30 UTC, Abby wrote:

>

I have a simple

dub.sdl

name "test"
targetType "executable"
buildOptions "betterC"

shouldn't these variable declarations be extern ?

Try

module test;
import core.stdc.stdio : FILE, fprintf;

extern shared FILE* stderr;

extern(C) int main(string[] args)
{
	fprintf(stderr, "Test\n",);
	return 0;
}

to confirm if it is or not the extern problem

missing extern(C), it should be:

module test;
import core.stdc.stdio : FILE, fprintf;

extern(C) extern shared FILE* stderr;

extern(C) int main(string[] args)
{
	fprintf(stderr, "Test\n",);
	return 0;
}
February 02, 2022
On Wednesday, 2 February 2022 at 09:27:02 UTC, duser wrote:
>
> missing `extern(C)`, it should be:
>
> ```D
> module test;
> import core.stdc.stdio : FILE, fprintf;
>
> extern(C) extern shared FILE* stderr;
>
> extern(C) int main(string[] args)
> {
> 	fprintf(stderr, "Test\n",);
> 	return 0;
> }
> ```

pls.. not more 'extern's ... I'm seeing 'extern' everywhere now...

..I'm gunna puke if I see another one.

and no, that doesn't work either :-(
February 02, 2022
On Wednesday, 2 February 2022 at 10:53:56 UTC, forkit wrote:
> On Wednesday, 2 February 2022 at 09:27:02 UTC, duser wrote:
>>
>> missing `extern(C)`, it should be:
>>
>> ```D
>> module test;
>> import core.stdc.stdio : FILE, fprintf;
>>
>> extern(C) extern shared FILE* stderr;
>>
>> extern(C) int main(string[] args)
>> {
>> 	fprintf(stderr, "Test\n",);
>> 	return 0;
>> }
>> ```
>
> pls.. not more 'extern's ... I'm seeing 'extern' everywhere now...
>
> ..I'm gunna puke if I see another one.
>
> and no, that doesn't work either :-(

extern(C) should imply extern in my book. I'm not sure if it does, but it seems wrong if it doesn't.
« First   ‹ Prev
1 2 3 4