I tried running ghc to compile a haskell program, and I get the following error:
$ ghc --make main
Linking main ...
ld: building for macOS, but linking in object file built for iOS Simulator, file 'main.o' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
`clang' failed in phase `Linker'. (Exit code: 1)
Here are some details about my machine:
macOS Catalina 10.15.7
Xcode 12.2
The Xcode developer tools were installed with xcode-select --install
I installed ghc with brew install ghc
Some other output that might be relevant:
$ gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.0 (clang-1200.0.32.27)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
If I run ghc --make main -v, this is what the output looks like right before it fails (apologies for the long line, not sure how to format this better):
clang -o main -fno-common -U__PIC__ -D__PIC__ -Wl,-no_compact_unwind main.o -L/usr/local/Cellar/ghc/8.10.1_2/lib/ghc-8.10.1/base-4.14.0.0 -L/usr/local/Cellar/ghc/8.10.1_2/lib/ghc-8.10.1/integer-gmp-1.0.3.0 -L/usr/local/Cellar/ghc/8.10.1_2/libexec/integer-gmp/lib -L/usr/local/Cellar/ghc/8.10.1_2/lib/ghc-8.10.1/ghc-prim-0.6.1 -L/usr/local/Cellar/ghc/8.10.1_2/lib/ghc-8.10.1/rts /var/folders/5j/wwtlv8lx0m5fmhc3hy5w5_000000gp/T/ghc49162_0/ghc_2.o -Wl,-u,_base_GHCziTopHandler_runIO_closure -Wl,-u,_base_GHCziTopHandler_runNonIO_closure -Wl,-u,_ghczmprim_GHCziTuple_Z0T_closure -Wl,-u,_ghczmprim_GHCziTypes_True_closure -Wl,-u,_ghczmprim_GHCziTypes_False_closure -Wl,-u,_base_GHCziPack_unpackCString_closure -Wl,-u,_base_GHCziWeak_runFinalizzerBatch_closure -Wl,-u,_base_GHCziIOziException_stackOverflow_closure -Wl,-u,_base_GHCziIOziException_heapOverflow_closure -Wl,-u,_base_GHCziIOziException_allocationLimitExceeded_closure -Wl,-u,_base_GHCziIOziException_blockedIndefinitelyOnMVar_closure -Wl,-u,_base_GHCziIOziException_blockedIndefinitelyOnSTM_closure -Wl,-u,_base_GHCziIOziException_cannotCompactFunction_closure -Wl,-u,_base_GHCziIOziException_cannotCompactPinned_closure -Wl,-u,_base_GHCziIOziException_cannotCompactMutable_closure -Wl,-u,_base_ControlziExceptionziBase_absentSumFieldError_closure -Wl,-u,_base_ControlziExceptionziBase_nonTermination_closure -Wl,-u,_base_ControlziExceptionziBase_nestedAtomically_closure -Wl,-u,_base_GHCziEventziThread_blockedOnBadFD_closure -Wl,-u,_base_GHCziConcziSync_runSparks_closure -Wl,-u,_base_GHCziConcziIO_ensureIOManagerIsRunning_closure -Wl,-u,_base_GHCziConcziIO_ioManagerCapabilitiesChanged_closure -Wl,-u,_base_GHCziConcziSignal_runHandlersPtr_closure -Wl,-u,_base_GHCziTopHandler_flushStdHandles_closure -Wl,-u,_base_GHCziTopHandler_runMainIO_closure -Wl,-u,_ghczmprim_GHCziTypes_Czh_con_info -Wl,-u,_ghczmprim_GHCziTypes_Izh_con_info -Wl,-u,_ghczmprim_GHCziTypes_Fzh_con_info -Wl,-u,_ghczmprim_GHCziTypes_Dzh_con_info -Wl,-u,_ghczmprim_GHCziTypes_Wzh_con_info -Wl,-u,_base_GHCziPtr_Ptr_con_info -Wl,-u,_base_GHCziPtr_FunPtr_con_info -Wl,-u,_base_GHCziInt_I8zh_con_info -Wl,-u,_base_GHCziInt_I16zh_con_info -Wl,-u,_base_GHCziInt_I32zh_con_info -Wl,-u,_base_GHCziInt_I64zh_con_info -Wl,-u,_base_GHCziWord_W8zh_con_info -Wl,-u,_base_GHCziWord_W16zh_con_info -Wl,-u,_base_GHCziWord_W32zh_con_info -Wl,-u,_base_GHCziWord_W64zh_con_info -Wl,-u,_base_GHCziStable_StablePtr_con_info -Wl,-u,_hs_atomic_add8 -Wl,-u,_hs_atomic_add16 -Wl,-u,_hs_atomic_add32 -Wl,-u,_hs_atomic_add64 -Wl,-u,_hs_atomic_sub8 -Wl,-u,_hs_atomic_sub16 -Wl,-u,_hs_atomic_sub32 -Wl,-u,_hs_atomic_sub64 -Wl,-u,_hs_atomic_and8 -Wl,-u,_hs_atomic_and16 -Wl,-u,_hs_atomic_and32 -Wl,-u,_hs_atomic_and64 -Wl,-u,_hs_atomic_nand8 -Wl,-u,_hs_atomic_nand16 -Wl,-u,_hs_atomic_nand32 -Wl,-u,_hs_atomic_nand64 -Wl,-u,_hs_atomic_or8 -Wl,-u,_hs_atomic_or16 -Wl,-u,_hs_atomic_or32 -Wl,-u,_hs_atomic_or64 -Wl,-u,_hs_atomic_xor8 -Wl,-u,_hs_atomic_xor16 -Wl,-u,_hs_atomic_xor32 -Wl,-u,_hs_atomic_xor64 -Wl,-u,_hs_cmpxchg8 -Wl,-u,_hs_cmpxchg16 -Wl,-u,_hs_cmpxchg32 -Wl,-u,_hs_cmpxchg64 -Wl,-u,_hs_atomicread8 -Wl,-u,_hs_atomicread16 -Wl,-u,_hs_atomicread32 -Wl,-u,_hs_atomicread64 -Wl,-u,_hs_atomicwrite8 -Wl,-u,_hs_atomicwrite16 -Wl,-u,_hs_atomicwrite32 -Wl,-u,_hs_atomicwrite64 -Wl,-search_paths_first -Wl,-dead_strip -lHSbase-4.14.0.0 -lHSinteger-gmp-1.0.3.0 -lHSghc-prim-0.6.1 -lHSrts -lCffi -liconv -lgmp -lm -ldl -Wl,-dead_strip_dylibs
ld: building for macOS, but linking in object file built for iOS Simulator, file 'main.o' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I have issues building ace 5.3 in linux. I get the following error.
g++ -W -Wall -Wpointer-arith -pipe -O3 -g -Wno-uninitialized -fno-implicit-templates -DACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION -D_POSIX_THREADS -D_POSIX_THREAD_SAFE_FUNCTIONS -D_REENTRANT -I/home/vwickram/Ubuntu_Release/tmp/ACE_wrappers -DACE_HAS_EXCEPTIONS -L/home/vwickram/Ubuntu_Release/tmp/ACE_wrappers/ace -L./ -o gperf .obj/gperf.o .obj/Options.o .obj/Iterator.o .obj/Gen_Perf.o .obj/Key_List.o .obj/List_Node.o .obj/Hash_Table.o .obj/Bool_Array.o .obj/Vectors.o .obj/Version.o -lACE -ldl -lpthread
/home/vwickram/Ubuntu_Release/tmp/ACE_wrappers/ace/libACE.so: undefined reference to `aio_return'
/home/vwickram/Ubuntu_Release/tmp/ACE_wrappers/ace/libACE.so: undefined reference to `aio_read'
/home/vwickram/Ubuntu_Release/tmp/ACE_wrappers/ace/libACE.so: undefined reference to `aio_cancel'
/home/vwickram/Ubuntu_Release/tmp/ACE_wrappers/ace/libACE.so: undefined reference to `aio_error'
/home/vwickram/Ubuntu_Release/tmp/ACE_wrappers/ace/libACE.so: undefined reference to `aio_write'
/home/vwickram/Ubuntu_Release/tmp/ACE_wrappers/ace/libACE.so: undefined reference to `aio_suspend'
collect2: ld returned 1 exit status
make[2]: *** [gperf] Error 1
make[2]: Leaving directory `/home/vwickram/Ubuntu_Release/tmp/ACE_wrappers/apps/gperf/src'
make[1]: *** [src.subdir] Error 2
make[1]: Leaving directory `/home/vwickram/Ubuntu_Release/tmp/ACE_wrappers/apps/gperf'
make: *** [all.nested] Error 2
When I googled I found out it is a bug in ace5.3 and it is fixed in later versions. So I got the ace 6.3 version and managed to build in linux. However, ace 6.3 wouldn't build in SolarisX86 with sunstudio 11 compiler. I get the following.
ACE::Monitor_Control::Monitor_Point_Registry*ACE_Singleton<ACE::Monitor_Control::Monitor_Point_Registry,ACE_Thread_Mutex>::instance() /home/vwickram/Ubuntu_Release/ace6.3/tmp/ACE_wrappers/lib/libACE.so
ld: fatal: Symbol referencing errors. No output written to ace_gperf
gmake[1]: *** [ace_gperf] Error 1
gmake[1]: Leaving directory `/home/vwickram/Ubuntu_Release/ace6.3/tmp/ACE_wrappers/apps/gperf/src'
gmake: *** [gperf] Error 2
Could someone help please? I would still prefer using ace 5.3 version and use a patch to fix the bug and make it build on linux.
I faced a similar issue on ubuntu 14.04 for Ace 5.5.
I checked the whole console log and it couldnt find librt.so in /usr/lib and librt.so.1 in /lib/
I searched for these and found them in /usr/lib/x86_64-linux-gnu/librt.so and /lib/x86_64-linux-gnu/librt.so.1
I copied them to respected folders and then it worked fine without any errors.
On i386 librt is found in /usr/lib/i386-linux-gnu/librt.so
Install the asynchronous library.
For example in Fedora-linux it'll be libaio-devel. (Mostly not needed, but some issues may occur if not installed)
After Installing compile with the following flags.
cc file.c -lrt
-lrt - link (lrt)read time library.