ldc-developers / ldc2.snap

Snap package definition for LDC, the LLVM-based D compiler
11 stars 4 forks source link

--link-internally fails to find system libraries #103

Closed WebDrake closed 4 years ago

WebDrake commented 4 years ago

The following errors result when trying to build a simple "Hello World" with the internal LLD:

$ ldc2 --link-internally hello.d
lld: error: unable to find library -lrt
lld: error: unable to find library -ldl
lld: error: unable to find library -lpthread
lld: error: unable to find library -lm
Error: linking with LLD failed

This suggests that the internal LLD does not by default have enough info to know where to look for system libraries.

In principle it could use either the host system's libs, or those in the core snap.

WebDrake commented 4 years ago
Explicitly specifying the path to host system libs (on an Ubuntu 18.04 install) gets rid of the "unable to find" errors but results in a very extensive list of undefined symbol errors. ``` $ ldc2 --link-internally -L-L/usr/lib/x86_64-linux-gnu hello.d lld: error: undefined symbol: fwrite >>> referenced by hello.d >>> hello.o:(_D3std5stdio__T13trustedFwriteTaZQsFNbNiNePOS4core4stdcQBx8_IO_FILExAaZm) >>> referenced by stdio.d >>> stdio.o:(_D3std5stdio4File17LockingTextWriter__T3putTAxaZQjMFNfMQlZv) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by stdio.d >>> stdio.o:(_D3std5stdio4File17LockingTextWriter__T3putTAaZQiMFNfMQkZv) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by minfo.d >>> minfo.o:(_D2rt5minfo11ModuleGroup9sortCtorsMFAyaZv) in archive /snap/ldc2/x4/bin/../lib64/libdruntime-ldc.a >>> referenced by profilegc.d >>> profilegc.o:(_D2rt9profilegc25_sharedStaticDtor_L115_C1FZv) in archive /snap/ldc2/x4/bin/../lib64/libdruntime-ldc.a >>> referenced by dwarfeh.d >>> dwarfeh.o:(_d_throw_exception) in archive /snap/ldc2/x4/bin/../lib64/libdruntime-ldc.a >>> referenced by dwarfeh.d >>> dwarfeh.o:(_d_eh_personality_common) in archive /snap/ldc2/x4/bin/../lib64/libdruntime-ldc.a >>> referenced by dwarfeh.d >>> dwarfeh.o:(_d_eh_personality_common) in archive /snap/ldc2/x4/bin/../lib64/libdruntime-ldc.a >>> referenced by dwarfeh.d >>> dwarfeh.o:(_D2rt7dwarfeh8scanLSDAFPxhmmbbPSQBe6unwind17_Unwind_ExceptionJmJiZEQCnQCn10LsdaResult) in archive /snap/ldc2/x4/bin/../lib64/libdruntime-ldc.a lld: error: undefined symbol: memcpy >>> referenced by hello.d >>> hello.o:(_D3std9exception__T7bailOutHTCQBcQBb14ErrnoExceptionZQBiFNfAyamMAxaZv) >>> referenced by hello.d >>> hello.o:(_D6object__T4_dupTxaTyaZQmFNaNbAxaZAya) >>> referenced by interfaces.d >>> interfaces.o:(_D6object__T3dupTaZQhFNaNbNdNfAxaZAa) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by interfaces.d >>> interfaces.o:(_D6object__T4idupTaZQiFNaNbNdNfAaZAya) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by cstring.d >>> cstring.o:(_D3std8internal7cstring__T11tempCStringTaTAxaZQuFNaNbNiNfMQqZSQCiQChQCb__T17TempCStringBufferTaZQw) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by conv.d >>> conv.o:(_D3std4conv__T7emplaceTCQw12experimental6logger10filelogger10FileLoggerTSQCt5stdio4FileTEQDjQCoQCd4core8LogLevelZQDvFAvKQBwQBjZQEa) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by concurrency.d >>> concurrency.o:(_D3std11concurrency15ThreadScheduler5spawnMFDFZvZv) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by concurrency.d >>> concurrency.o:(_DThn16_3std11concurrency15ThreadScheduler5spawnMFDFZvZv) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by concurrency.d >>> concurrency.o:(_D3std11concurrency10MessageBox3putMFKSQBlQBk7MessageZv) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by parallelism.d >>> parallelism.o:(_D3std11parallelism8TaskPool6__ctorMFNemZCQBoQBnQBd) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced 82 more times lld: error: undefined symbol: fputc_unlocked >>> referenced by hello.d >>> hello.o:(_D3std5stdio4File17LockingTextWriter__T3putTyaZQiMFNfyaZ12trustedFPUTCFNbNiNeiPS4core4stdcQDg8_IO_FILEZi) >>> referenced by hello.d >>> hello.o:(_D3std5stdio4File17LockingTextWriter__T3putTaZQhMFNfaZ12trustedFPUTCFNbNiNeiPS4core4stdcQDe8_IO_FILEZi) >>> referenced by stdio.d >>> stdio.o:(_D3std5stdio4File17LockingTextWriter__T3putTAxaZQjMFNfMQlZv) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by stdio.d >>> stdio.o:(_D3std5stdio4File17LockingTextWriter__T3putTxaZQiMFNfxaZv) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by stdio.d >>> stdio.o:(_D3std5stdio4File17LockingTextWriter__T3putTxwZQiMFNfxwZv) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by stdio.d >>> stdio.o:(_D3std5stdio4File17LockingTextWriter__T3putTxwZQiMFNfxwZv) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by stdio.d >>> stdio.o:(_D3std5stdio4File17LockingTextWriter__T3putTAaZQiMFNfMQkZv) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by stdio.d >>> stdio.o:(_D3std5stdio4File17LockingTextWriter__T3putTwZQhMFNfwZv) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by stdio.d >>> stdio.o:(_D3std5stdio4File17LockingTextWriter__T3putTwZQhMFNfwZv) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a lld: error: undefined symbol: fputwc_unlocked >>> referenced by hello.d >>> hello.o:(_D3std5stdio4File17LockingTextWriter__T3putTyaZQiMFNfyaZ13trustedFPUTWCFNbNiNewPS4core4stdcQDh8_IO_FILEZi) >>> referenced by hello.d >>> hello.o:(_D3std5stdio4File17LockingTextWriter__T3putTaZQhMFNfaZ13trustedFPUTWCFNbNiNewPS4core4stdcQDf8_IO_FILEZi) >>> referenced by stdio.d >>> stdio.o:(_D3std5stdio4File17LockingTextWriter__T3putTAxaZQjMFNfMQlZv) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by stdio.d >>> stdio.o:(_D3std5stdio4File17LockingTextWriter__T3putTxaZQiMFNfxaZv) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by stdio.d >>> stdio.o:(_D3std5stdio4File17LockingTextWriter__T3putTxwZQiMFNfxwZv) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by stdio.d >>> stdio.o:(_D3std5stdio4File17LockingTextWriter__T3putTAaZQiMFNfMQkZv) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by stdio.d >>> stdio.o:(_D3std5stdio4File17LockingTextWriter__T3putTwZQhMFNfwZv) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a lld: error: undefined symbol: strerror_r >>> referenced by exception.d >>> exception.o:(_D3std9exception14ErrnoException6__ctorMFNfAyaQdmZCQBxQBwQBp) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by socket.d >>> socket.o:(_D3std6socket17formatSocketErrorFNeiZAya) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by socket.d >>> socket.o:(_D3std6socket13HostException8__mixin16__ctorMFNfAyaQdmC6object9ThrowableiZCQCvQCuQCq) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by socket.d >>> socket.o:(_D3std6socket16AddressException8__mixin16__ctorMFNfAyaQdmC6object9ThrowableiZCQCyQCxQCt) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by socket.d >>> socket.o:(_D3std6socket16AddressException8__mixin16__ctorMFNfAyaiQemC6object9ThrowableZCQCyQCxQCt) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by socket.d >>> socket.o:(_D3std6socket21SocketAcceptException8__mixin16__ctorMFNfAyaQdmC6object9ThrowableiZCQDdQDcQCy) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by socket.d >>> socket.o:(_D3std6socket6Socket12getErrorTextMFNfZAya) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a lld: error: undefined symbol: strlen >>> referenced by exception.d >>> exception.o:(_D3std9exception14ErrnoException6__ctorMFNfAyaQdmZCQBxQBwQBp) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by conv.d >>> conv.o:(_D3std4conv__T2toTAyaZ__TQlTPxaZQsFNaNbQlZQy) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by conv.d >>> conv.o:(_D3std4conv__T2toTAyaZ__TQlTPaZQrFNaNbQkZQx) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by socket.d >>> socket.o:(_D3std6socket17formatSocketErrorFNeiZAya) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by socket.d >>> socket.o:(_D3std6socket13HostException8__mixin16__ctorMFNfAyaQdmC6object9ThrowableiZCQCvQCuQCq) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by socket.d >>> socket.o:(_D3std6socket16AddressException8__mixin16__ctorMFNfAyaQdmC6object9ThrowableiZCQCyQCxQCt) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by socket.d >>> socket.o:(_D3std6socket16AddressException8__mixin16__ctorMFNfAyaiQemC6object9ThrowableZCQCyQCxQCt) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by socket.d >>> socket.o:(_D3std6socket7Address12toHostStringMxFNebZAya) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by socket.d >>> socket.o:(_D3std6socket7Address15toServiceStringMxFNebZAya) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by socket.d >>> socket.o:(_D3std6socket21SocketAcceptException8__mixin16__ctorMFNfAyaQdmC6object9ThrowableiZCQDdQDcQCy) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced 9 more times lld: error: undefined symbol: bcmp >>> referenced by interfaces.d >>> interfaces.o:(_D4core8internal5array8equality__T8__equalsTyaTyaZQqFNaNbNiNfAyaQdZb) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by interfaces.d >>> interfaces.o:(_D4core8internal5array8equality__T8__equalsTxaTxaZQqFNaNbNiNfAxaQdZb) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by object.d >>> object.o:(_D6object15TypeInfo_Struct6equalsMxFNaNbNexPvxQdZb) in archive /snap/ldc2/x4/bin/../lib64/libdruntime-ldc.a >>> referenced by ti_Along.d >>> ti_Along.o:(_D2rt8typeinfo8ti_Along11TypeInfo_Al6equalsMxFxPvxQdZb) in archive /snap/ldc2/x4/bin/../lib64/libdruntime-ldc.a >>> referenced by ti_Ashort.d >>> ti_Ashort.o:(_D2rt8typeinfo9ti_Ashort11TypeInfo_As6equalsMxFxPvxQdZb) in archive /snap/ldc2/x4/bin/../lib64/libdruntime-ldc.a >>> referenced by ti_Ag.d >>> ti_Ag.o:(_D2rt8typeinfo5ti_Ag11TypeInfo_Ag6equalsMxFxPvxQdZb) in archive /snap/ldc2/x4/bin/../lib64/libdruntime-ldc.a >>> referenced by ti_Aint.d >>> ti_Aint.o:(_D2rt8typeinfo7ti_Aint11TypeInfo_Ai6equalsMxFxPvxQdZb) in archive /snap/ldc2/x4/bin/../lib64/libdruntime-ldc.a lld: error: undefined symbol: _Unwind_Resume >>> referenced by variant.d >>> variant.o:(_D3std7variant__T8VariantNVmi32ZQp__T7handlerHTvZQmFEQBzQBy__TQBtVmi32ZQCc4OpIDPG32hPvZl) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by variant.d >>> variant.o:(_D3std7variant__T8VariantNVmi32ZQp4typeMxFNbNdNeZC8TypeInfo) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by variant.d >>> variant.o:(_D3std7variant__T8VariantNVmi32ZQp__T5opCmpTSQBrQBq__TQBlVmi32ZQBuZQBeMFQBcZi) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by variant.d >>> variant.o:(_D3std7variant__T8VariantNVmi32ZQp6toHashMxFNbNfZm) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by variant.d >>> variant.o:(_D3std7variant__T8VariantNVmi32ZQp__T7handlerTSQBt11concurrency3TidZQBfFEQCtQCs__TQCnVmi32ZQCw4OpIDPG32hPvZl) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by variant.d >>> variant.o:(_D3std7variant__T8VariantNVmi32ZQp__T7handlerTSQBt11concurrency3TidZQBfFEQCtQCs__TQCnVmi32ZQCw4OpIDPG32hPvZl) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by systime.d >>> systime.o:(_D3std8datetime7systime7SysTime6__ctorMFNbNcNfSQBtQBs4date4DateyCQClQCk8timezone8TimeZoneZSQDlQDkQDeQCz) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by systime.d >>> systime.o:(_D3std8datetime7systime7SysTime__T6opCastTSQBpQBo4date8DateTimeZQBeMxFNbNlNfZQBj) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by timezone.d >>> timezone.o:(_D3std8datetime8timezone9LocalTime6hasDSTMxFNbNdNeZb) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by cstring.d >>> cstring.o:(_D3std8internal7cstring__T11tempCStringTaTAxaZQuFNaNbNiNfMQqZSQCiQChQCb__T17TempCStringBufferTaZQw) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced 93 more times lld: error: undefined symbol: memcmp >>> referenced by package.d >>> package.o:(_D4core8internal6string__T7dstrcmpZQjFNaNbNiNeMxAaMxQeZi) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by object.d >>> object.o:(_D6object15TypeInfo_Struct7compareMxFNaNbNexPvxQdZi) in archive /snap/ldc2/x4/bin/../lib64/libdruntime-ldc.a lld: error: undefined symbol: tzname >>> referenced by timezone.d >>> timezone.o:(_D3std8datetime8timezone9LocalTime7stdNameMxFNbNdNeZAya) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by timezone.d >>> timezone.o:(_D3std8datetime8timezone9LocalTime7dstNameMxFNbNdNeZAya) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a lld: error: undefined symbol: localtime_r >>> referenced by timezone.d >>> timezone.o:(_D3std8datetime8timezone9LocalTime11dstInEffectMxFNbNelZb) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by timezone.d >>> timezone.o:(_D3std8datetime8timezone9LocalTime7utcToTZMxFNbNelZl) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by timezone.d >>> timezone.o:(_D3std8datetime8timezone9LocalTime7tzToUTCMxFNbNelZl) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by timezone.d >>> timezone.o:(_D3std8datetime8timezone9LocalTime7tzToUTCMxFNbNelZl) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by timezone.d >>> timezone.o:(_D3std8datetime8timezone9LocalTime7tzToUTCMxFNbNelZl) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a lld: error: undefined symbol: tzset >>> referenced by timezone.d >>> timezone.o:(_D3std8datetime8timezone9LocalTime9singletonFNeZ12__dgliteral4MFNaNbNiNfZOb) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a lld: error: undefined symbol: malloc >>> referenced by memory.d >>> memory.o:(_D3std8internal6memory__T13enforceMallocZQqFNaNbNiNfmZPv) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by zutil.c >>> zutil.c.o:(zcalloc) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by gc.d >>> gc.o:(_D2gc4impl12conservativeQw10initializeFZC4coreQBs11gcinterface2GC) in archive /snap/ldc2/x4/bin/../lib64/libdruntime-ldc.a >>> referenced by gc.d >>> gc.o:(_D2gc4impl12conservativeQw18initialize_preciseFZC4coreQCa11gcinterface2GC) in archive /snap/ldc2/x4/bin/../lib64/libdruntime-ldc.a >>> referenced by gc.d >>> gc.o:(_D2gc4impl12conservativeQw4Pool10initializeMFNbmbZv) in archive /snap/ldc2/x4/bin/../lib64/libdruntime-ldc.a >>> referenced by gc.d >>> gc.o:(_D2gc4impl12conservativeQw4Pool10initializeMFNbmbZv) in archive /snap/ldc2/x4/bin/../lib64/libdruntime-ldc.a >>> referenced by gc.d >>> gc.o:(_D2gc4impl12conservativeQw4Pool10initializeMFNbmbZv) in archive /snap/ldc2/x4/bin/../lib64/libdruntime-ldc.a >>> referenced by gc.d >>> gc.o:(_D2gc4impl6manualQp10initializeFZC4coreQBl11gcinterface2GC) in archive /snap/ldc2/x4/bin/../lib64/libdruntime-ldc.a >>> referenced by gc.d >>> gc.o:(_D2gc4impl6manualQp8ManualGC6mallocMFNbmkxC8TypeInfoZPv) in archive /snap/ldc2/x4/bin/../lib64/libdruntime-ldc.a >>> referenced by gc.d >>> gc.o:(_DThn16_2gc4impl6manualQp8ManualGC6mallocMFNbmkxC8TypeInfoZPv) in archive /snap/ldc2/x4/bin/../lib64/libdruntime-ldc.a >>> referenced 38 more times lld: error: undefined symbol: free >>> referenced by concurrency.d >>> concurrency.o:(_D4core6memory__T8pureFreeZQkFNaNbNiPvZv) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by stdio.d >>> stdio.o:(_D3std5stdio4File6detachMFNeZv) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by stdio.d >>> stdio.o:(_D3std5stdio4File6detachMFNeZv) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by zutil.c >>> zutil.c.o:(zcfree) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by gc.d >>> gc.o:(_D2gc4impl12conservativeQw14ConservativeGC6__dtorMFZv) in archive /snap/ldc2/x4/bin/../lib64/libdruntime-ldc.a >>> referenced by gc.d >>> gc.o:(_D2gc4impl12conservativeQw3Gcx4DtorMFZv) in archive /snap/ldc2/x4/bin/../lib64/libdruntime-ldc.a >>> referenced by gc.d >>> gc.o:(_D2gc4impl12conservativeQw14ConservativeGC__T9runLockedS_DQCeQCeQCcQCnQBs8minimizeMFNbZ2goFNbPSQDpQDpQDnQDy3GcxZvS_DQEkQEkQEiQEt9otherTimelS_DQFkQFkQFiQFt9numOtherslTQCvZQEvMFNbKQDhZv) in archive /snap/ldc2/x4/bin/../lib64/libdruntime-ldc.a >>> referenced by gc.d >>> gc.o:(_D2gc4impl12conservativeQw3Gcx19_d_gcx_atfork_childUZv) in archive /snap/ldc2/x4/bin/../lib64/libdruntime-ldc.a >>> referenced by gc.d >>> gc.o:(_D2gc4impl12conservativeQw3Gcx15stopScanThreadsMFNbZv) in archive /snap/ldc2/x4/bin/../lib64/libdruntime-ldc.a >>> referenced by gc.d >>> gc.o:(_D2gc4impl12conservativeQw4Pool4DtorMFNbZv) in archive /snap/ldc2/x4/bin/../lib64/libdruntime-ldc.a >>> referenced 60 more times lld: error: undefined symbol: sched_getaffinity >>> referenced by parallelism.d >>> parallelism.o:(_D3std11parallelism8TaskPool6__ctorMFNeZCQBnQBmQBc) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a lld: error: undefined symbol: sysconf >>> referenced by parallelism.d >>> parallelism.o:(_D3std11parallelism8TaskPool6__ctorMFNeZCQBnQBmQBc) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a >>> referenced by thread.d >>> thread.o:(_D4core6thread26_sharedStaticCtor_L3901_C1FZv) in archive /snap/ldc2/x4/bin/../lib64/libdruntime-ldc.a >>> referenced by thread.d >>> thread.o:(_D4core6thread26_sharedStaticCtor_L3901_C1FZv) in archive /snap/ldc2/x4/bin/../lib64/libdruntime-ldc.a >>> referenced by elf.d >>> elf.o:(_D2rt9backtrace3elf7ElfFile8openSelfFNbNiPSQBpQBpQBiQBhZb) in archive /snap/ldc2/x4/bin/../lib64/libdruntime-ldc.a >>> referenced by elf.d >>> elf.o:(_D2rt9backtrace3elf5Image23getDebugLineSectionDataMFZAxh) in archive /snap/ldc2/x4/bin/../lib64/libdruntime-ldc.a >>> referenced by elf.d >>> elf.o:(_D2rt9backtrace3elf5Image23getDebugLineSectionDataMFZAxh) in archive /snap/ldc2/x4/bin/../lib64/libdruntime-ldc.a >>> referenced by elf.d >>> elf.o:(_D2rt9backtrace3elf5Image23getDebugLineSectionDataMFZAxh) in archive /snap/ldc2/x4/bin/../lib64/libdruntime-ldc.a >>> referenced by elf.d >>> elf.o:(_D2rt9backtrace3elf5Image23getDebugLineSectionDataMFZAxh) in archive /snap/ldc2/x4/bin/../lib64/libdruntime-ldc.a >>> referenced by elf.d >>> elf.o:(_D2rt9backtrace3elf17findSectionByNameFNbNiPxSQBsQBsQBl7ElfFilePSQClQClQCe10ElfSectionAxaZm) in archive /snap/ldc2/x4/bin/../lib64/libdruntime-ldc.a lld: error: undefined symbol: getnameinfo >>> referenced by socket.d >>> socket.o:(_D3std6socket25_sharedStaticCtor_L282_C1FZv) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a lld: error: undefined symbol: getaddrinfo >>> referenced by socket.d >>> socket.o:(_D3std6socket25_sharedStaticCtor_L282_C1FZv) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a lld: error: undefined symbol: freeaddrinfo >>> referenced by socket.d >>> socket.o:(_D3std6socket25_sharedStaticCtor_L282_C1FZv) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a lld: error: undefined symbol: getprotobyname >>> referenced by socket.d >>> socket.o:(_D3std6socket8Protocol17getProtocolByNameMFNbNeMAxaZb) in archive /snap/ldc2/x4/bin/../lib64/libphobos2-ldc.a lld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors) ```
WebDrake commented 4 years ago

Explicitly specifying the path to the core-snap library locations results in the libraries not being found:

$ ldc2 --link-internally -L-L/snap/core/current/lib/x86_64-linux-gnu hello.d
lld: error: unable to find library -lrt
lld: error: unable to find library -ldl
lld: error: unable to find library -lpthread
lld: error: unable to find library -lm
Error: linking with LLD failed

This is particularly odd, because the libraries in question are indeed present there.

WebDrake commented 4 years ago

(A minor note: using --link-internal also bumps into the ldc2.conf problem described in https://github.com/ldc-developers/ldc2.snap/issues/102, but this we can treat separately.)

WebDrake commented 4 years ago

The same errors happen when using --link-internally with e.g. the upstream 1.20.0 binary package. So this is likely not an issue with the snap package per se.

kinke commented 4 years ago

-link-internally isn't really supposed to work without adding a bunch of linker options otherwise implicitly added by the C compiler for Linux and BSDs, see https://github.com/ldc-developers/ldc/pull/2203#issuecomment-381366375.

WebDrake commented 4 years ago

Thanks for the pointer. One thing I don't quite understand there is the need for the manual -L options given that the linker call does automatically reference the system libraries, e.g. with the current snap package, ldc2 -link-internally -v hello.d results in a linker command:

lld hello.o -o hello -L/snap/ldc2/115/bin/../lib64 -L/snap/ldc2/115/bin/../lib32 --no-warn-search-mismatch -lphobos2-ldc -ldruntime-ldc --gc-sections -lrt -ldl -lpthread -lm 
lld: error: unknown argument '--no-warn-search-mismatch'
lld: error: unable to find library -lrt
lld: error: unable to find library -ldl
lld: error: unable to find library -lpthread
lld: error: unable to find library -lm
Error: linking with LLD failed

I take it that what's missing are some extra flags referred to in the PR you linked to, but it's not 100% obvious which. Bear in mind that in the above example I'm trying to build for the regular host system, not cross-compiling for ARM.

A regular ldc2 -v hello.d gives this for the GCC linker command:

/usr/bin/gcc hello.o -o hello -fuse-ld=gold -L/snap/ldc2/115/bin/../lib64 -L/snap/ldc2/115/bin/../lib32 -Xlinker --no-warn-search-mismatch -lphobos2-ldc -ldruntime-ldc -Wl,--gc-sections -lrt -ldl -lpthread -lm -m64 

... which isn't very revealing, but ldc2 -v -L-v hello.d gets more detail:

/usr/bin/ld.gold -plugin /usr/lib/gcc/x86_64-linux-gnu/5/liblto_plugin.so -plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper -plugin-opt=-fresolution=/tmp/ccMbakM2.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --sysroot=/ --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed -dynamic-linker /lib64/ld-linux-x86-64.so.2 -z relro -o hello /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/5/crtbegin.o -L/snap/ldc2/115/bin/../lib64 -L/snap/ldc2/115/bin/../lib32 -L/usr/lib/gcc/x86_64-linux-gnu/5 -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/5/../../.. hello.o -v --no-warn-search-mismatch -lphobos2-ldc -ldruntime-ldc --gc-sections -lrt -ldl -lpthread -lm -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-linux-gnu/5/crtend.o /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crtn.o

I'll go through this and see if I can come up with a matching list for what's needed here.

Anyway, this clearly isn't a snap package issue. Would some extra upstream docs be welcome/useful at this stage, or is this enough of a moving target that it's best to hold off for now until further technical developments have happened upstream?

kinke commented 4 years ago

There's an open issue about this, and it's unlikely to be supported soon/at all due to the heterogeneous posix environments.

WebDrake commented 4 years ago

Thanks. I've subscribed to the upstream issue, and will close this now.