strange -fPIC compilation error
Charles Hixson via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Oct 30 18:30:45 PDT 2016
On 10/30/2016 05:14 PM, Lodovico Giaretta via Digitalmars-d-learn wrote:
> On Monday, 31 October 2016 at 00:08:59 UTC, Charles Hixson wrote:
>> So now I removed the repository version of dmd and dub, downloaded
>> DMD64 D Compiler v2.072.0-b2, used dkpg to install it, and appear to
>> get the same errors.
>>
>> (Well, actually I removed the commenting out of the code, but it
>> compiles and runs properly with ldc2.)
>
> I don't think it's a problem of DMD. This is due to your gcc
> installation being hardened, that is, configured to produce PIE by
> default. To produce PIE, the linker needs to be fed PIC, which DMD
> does not produce by default. The -fPIC flags makes DMD produce PIC out
> of your sources. The problem is, libphobos2.a (the static version of
> Phobos) is not compiled with -fPIC, so even if your code is PIC, gcc
> will complain. The workaround is to use -defaultlib=libphobos2.so to
> dynamically link with the shared version of Phobos. Being it a shared
> object, it does not give any problem with PIE.
>
> Looking on internet, I didn't find any clue about Debian shipping an
> hardened gcc, but this is the only cause I can think of for the
> behaviour you are experiencing.
>
Well, that certainly changed the error messages. With
dmd -defaultlib=/usr/lib/x86_64-linux-gnu/libphobos2.so test.d
I get:
/usr/include/dmd/druntime/import/core/stdc/stdio.d(1121): Error: found
'nothrow' when expecting '{'
/usr/include/dmd/druntime/import/core/stdc/stdio.d(1123): Error:
mismatched number of curly brackets
/usr/include/dmd/druntime/import/core/stdc/stdio.d(1124): Error:
mismatched number of curly brackets
/usr/include/dmd/druntime/import/core/stdc/stdio.d(1125): Error:
mismatched number of curly brackets
/usr/include/dmd/druntime/import/core/stdc/stdio.d(1126): Error:
mismatched number of curly brackets
/usr/include/dmd/druntime/import/core/stdc/stdio.d(1127): Error:
mismatched number of curly brackets
/usr/include/dmd/druntime/import/core/stdc/stdio.d(1128): Error:
mismatched number of curly brackets
/usr/include/dmd/druntime/import/core/stdc/stdio.d(1129): Error:
mismatched number of curly brackets
/usr/include/dmd/druntime/import/core/stdc/stdio.d(1133): Error: asm
statements must end in ';'
/usr/include/dmd/druntime/import/core/stdc/stdio.d(1136): Error: found
'private' instead of statement
/usr/include/dmd/druntime/import/core/stdc/stdio.d(1146): Error: no
identifier for declarator add
/usr/include/dmd/druntime/import/core/stdc/stdio.d(1149): Error: no
identifier for declarator usDone
/usr/include/dmd/druntime/import/core/stdc/stdio.d(1149): Error:
Declaration expected, not ':'
/usr/include/dmd/druntime/import/core/stdc/stdio.d(1157): Error:
Declaration expected, not '('
/usr/include/dmd/druntime/import/core/stdc/stdio.d(1159): Error:
Declaration expected, not 'foreach'
/usr/include/dmd/druntime/import/core/stdc/stdio.d(1159): Error:
Declaration expected, not '0'
/usr/include/dmd/druntime/import/core/stdc/stdio.d(1164): Error: no
identifier for declarator __fhnd_info[fd]
/usr/include/dmd/druntime/import/core/stdc/stdio.d(1164): Error:
Declaration expected, not '='
/usr/include/dmd/druntime/import/core/stdc/stdio.d(1165): Error:
Declaration expected, not 'return'
/usr/include/dmd/druntime/import/core/stdc/stdio.d(1167): Error:
unrecognized declaration
/usr/include/dmd/phobos/std/typecons.d(1124): Error: semicolon expected
following function declaration
More information about the Digitalmars-d-learn
mailing list