Swift compiler error at the time of compiling - swift

Trying to compile a .swift file using the swift compiler in Ubuntu 19.10 but facing this error at the time of compilation.
$ swiftc swift.swift
/usr/bin/ld.gold: fatal error: swift: open: Is a directory
clang-7: error: linker command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
I have also tried it with -v parameter and it shows this:
$ swiftc -v swift.swift
Swift version 5.1 (swift-5.1.2-RELEASE)
Target: x86_64-unknown-linux-gnu
/home/takshaksh/swift/usr/bin/swift -frontend -c -primary-file swift.swift -target x86_64-unknown-linux-gnu -disable-objc-interop -color-diagnostics -module-name swift -o /tmp/swift-2339bd.o
/home/takshaksh/swift/usr/bin/swift-autolink-extract /tmp/swift-2339bd.o -o /tmp/swift-0db3ba.autolink
/home/takshaksh/swift/usr/bin/clang++ -fuse-ld=gold -pie -target x86_64-unknown-linux-gnu -Xlinker -rpath -Xlinker /home/takshaksh/swift/usr/lib/swift/linux /home/takshaksh/swift/usr/lib/swift/linux/x86_64/swiftrt.o /tmp/swift-2339bd.o #/tmp/swift-0db3ba.autolink -L /home/takshaksh/swift/usr/lib/swift/linux -lswiftCore --target=x86_64-unknown-linux-gnu -v -o swift
clang version 7.0.0
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/takshaksh/swift/usr/bin
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.4.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Candidate multilib: .;#m64
Selected multilib: .;#m64
"/usr/bin/ld.gold" -pie --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o swift /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginS.o -L/home/takshaksh/swift/usr/lib/swift/linux -L/usr/lib/gcc/x86_64-linux-gnu/9 -L/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/9/../../.. -L/home/takshaksh/swift/usr/bin/../lib -L/lib -L/usr/lib -rpath /home/takshaksh/swift/usr/lib/swift/linux /home/takshaksh/swift/usr/lib/swift/linux/x86_64/swiftrt.o /tmp/swift-2339bd.o -lswiftSwiftOnoneSupport -lswiftCore -lswiftCore -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/9/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crtn.o
/usr/bin/ld.gold: fatal error: swift: open: Is a directory
clang-7: error: linker command failed with exit code 1 (use -v to see invocation)
:0: error: link command failed with exit code 1 (use -v to see invocation)

Related

Compiling perl Net::Interface module on CentOS 8.1 fails

I download the sources and manually tried to compile the perl Net::Interface module. Using CPAN to install the module gives the same error.
wget http://search.cpan.org/CPAN/authors/id/M/MI/MIKER/Net-Interface-1.016.tar.gz
tar xvfz Net-Interface-1.016.tar.gz
cd Net-Interface-1.016
perl Makefile.PL
Now this fails with the below error
checking for getnameinfo... yes
checking whether byte ordering is bigendian... no
checking for uint8_t... yes
checking size of uint8_t... configure: error: cannot compute sizeof (uint8_t)
See `config.log' for more details.
could not open config.h
config.log shows the below error
configure:10128: result: yes
configure:10135: checking size of uint8_t
configure:10437: gcc -o conftest -g -O2 -Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -fstack-protector-strong -L/usr/local/lib conftest.c >&5
/usr/bin/ld: /tmp/ccXH6miX.o: relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
configure:10440: $? = 1
configure: program exited with status 1
configure: failed program was:
| /* confdefs.h. */
| #define PACKAGE_NAME ""
| #define PACKAGE_TARNAME ""
| #define PACKAGE_VERSION ""
How can I fix this error? config.log seems to suggest to pass "-fPIC" flag but I am not sure how?
Thanks.
/usr/bin/ld: /tmp/ccXH6miX.o: relocation R_X86_64_32 against
`.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
The configure script needs to be run with --enable-shared for some reason (it is not necessary on Ubuntu). The following worked for me in a docker container with CentOS 8:
./configure --enable-shared
perl -I. Makefile.PL
make
sudo make install

linking problem, can't find symbol even though nm shows symbol in library

I'm linking an app against lflutter_linux_glfw. nm tools shows it has glad_glTexImage2D:
nm libflutter_linux_glfw.so | grep glTexImage2D
00000000034e87a0 b glad_glTexImage2D
00000000034e87a8 b glad_glTexImage2DMultisample
So I included lflutter_linux_glfw.so before flutter_video_renderer.o, and I get this:
clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.4.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0
Candidate multilib: .;#m64
Selected multilib: .;#m64
"/usr/bin/ld" -z relro --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o /home/dev/orwell/orwell_flutter/linux/../build/linux/debug/flutter_desktop_example
/usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../../x86_64-linux-gnu/crt1.o /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../../x86_64-linux-gnu/crti.o /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/crtbegin.o
-L/home/dev/orwell/orwell_flutter/linux/../build/linux/debug/lib -L/usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0 -L/usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../../x86_64-linux-gnu -L/lib/x86_64-linux-gnu
-L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../.. -L/usr/lib/llvm-6.0/bin/../lib -L/lib -L/usr/lib -lflutter_linux_glfw
/home/dev/orwell/orwell_flutter/linux/../build/linux/obj/main.o /home/dev/orwell/orwell_flutter/linux/../build/linux/obj/flutter/generated_plugin_registrant.o
/home/dev/orwell/orwell_flutter/linux/../build/linux/obj//home/dev/orwell/orwell_flutter/linux/flutter/ephemeral/cpp_client_wrapper_glfw/flutter_window_controller.o
/home/dev/orwell/orwell_flutter/linux/../build/linux/obj//home/dev/orwell/orwell_flutter/linux/flutter/ephemeral/cpp_client_wrapper_glfw/plugin_registrar.o
/home/dev/orwell/orwell_flutter/linux/../build/linux/obj//home/dev/orwell/orwell_flutter/linux/flutter/ephemeral/cpp_client_wrapper_glfw/engine_method_result.o
/home/dev/orwell/orwell_flutter/linux/../build/linux/obj//home/dev/orwell/orwell_flutter/linux/flutter/ephemeral/cpp_client_wrapper_glfw/standard_codec.o
/home/dev/orwell/orwell_flutter/linux/../build/linux/obj//home/dev/orwell/orwell_flutter/common/src/flutter_video_renderer.o
/home/dev/orwell/orwell_flutter/linux/../build/linux/obj//home/dev/orwell/orwell_flutter/common/src/flutter_texture_video_renderer.o
/home/dev/orwell/orwell_flutter/linux/../build/linux/obj//home/dev/orwell/orwell_flutter/common/src/flutter_orwell_plugin.o "-rpath=\$ORIGIN/lib" -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc
/usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/crtend.o /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../../x86_64-linux-gnu/crtn.o
/home/dev/orwell/orwell_flutter/linux/../build/linux/obj//home/dev/orwell/orwell_flutter/common/src/flutter_texture_video_renderer.o: In function
`flutter_orwell_plugin::FlutterTextureVideoRenderer::renderToTexture(unsigned long, unsigned long, unsigned int)':
flutter_texture_video_renderer.cc:(.text+0x1b6): undefined reference to `glad_glTexImage2D'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [/home/dev/orwell/orwell_flutter/linux/../build/linux/debug/flutter_desktop_example] Error 1
In other words, it complains there's no reference to glad_glTexImage2D even though it it indeed in
flutter_linux_glfw.so. I also tried adding flutter_linux_glfw.so after the flutter_texture_video_renderer.o but I get the same error
nm libflutter_linux_glfw.so | grep glTexImage2D
00000000034e87a0 b glad_glTexImage2D
00000000034e87a8 b glad_glTexImage2DMultisample
These symbols are local to the library (not exported from it).
You can see the list of exported symbols with:
nm -D libflutter_linux_glfw.so
You will observe that glad_glTexImage2D is not listed there.
P.S.
I included lflutter_linux_glfw.so before flutter_video_renderer.o
This is the opposite order of what you are supposed to do: libraries should follow the objects that refer to them (though this doesn't really matter for shared libraries).

Boost.Python Link Error with Python3 and virtualenv

I got the following error when I tried to compile .cpp file with clang++.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I set up Python and boost-python as follows.
Python
I installed Python 3.6.0 using pyenv-virtualenv (via homebrew)
Boost-Python
I used homebrew in Python 3 environment.
$ source activate py36
$ brew install boost-python --with-python3 --without-python
~/.bash_profile
My ~/.bash_profile looks like this:
export PYENV_ROOT="/usr/local/var/pyenv"
export PYENV_VIRTUALENV_DISABLE_PROMPT=1
export CPLUS_INCLUDE_PATH="$CPLUS_INCLUDE_PATH:/usr/local/var/pyenv/versions/3.6.0/include/python3.6m/"
if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi
if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)" ; fi
Test cpp
This is the file I tried to compile and failed (saved as test.cpp).
#define BOOST_PYTHON_STATIC_LIB
#include <boost/python.hpp>
using namespace boost::python;
char const* say(){
return "hello, world";
}
BOOST_PYTHON_MODULE( hello ){
boost::python::def( "say", say );
}
makefile
CC = clang++
INCLUDE = -I`python -c 'from distutils.sysconfig import *; print(get_python_inc())’`
BOOST = -lboost_python3.6 -lboost_serialization
FMATH = -fomit-frame-pointer -fno-operator-names -msse2 -mfpmath=sse -march=native
CFLAGS = -std=c++11 -L/usr/local/lib -O3
CFLAGS_SO = -shared -fPIC -std=c++11 -L/usr/local/lib -O3
LINK = -L/usr/local/Cellar/boost-python/1.64.0/lib/
install:
$(CC) test.cpp -o hello.so $(INCLUDE) $(BOOST) $(LINK) $(FMATH) $(CFLAGS_SO)
Error
make install returns this error.
clang++ test.cpp -o hello.so -I`python -c 'from distutils.sysconfig import *; print(get_python_inc())’` -lboost_python3.6 -lboost_serialization -L/usr/local/Cellar/boost-python/1.64.0/lib/ -fomit-frame-pointer -fno-operator-names -msse2 -mfpmath=sse -march=native -shared -fPIC -std=c++11 -L/usr/local/lib -O3 -v
/bin/sh: command substitution: line 0: unexpected EOF while looking for matching `''
/bin/sh: command substitution: line 1: syntax error: unexpected end of file
Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
clang -cc1 version 8.1.0 (clang-802.0.42) default target x86_64-apple-darwin16.6.0
ignoring nonexistent directory "-lboost_python3.6"
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here:
.
/usr/local/var/pyenv/versions/3.6.0/include/python3.6m
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.1.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -lto_library /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -dynamic -dylib -arch x86_64 -macosx_version_min 10.12.0 -o hello.so -L/usr/local/Cellar/boost-python/1.64.0/lib/ -L/usr/local/lib /var/folders/rm/qv81g4ss29j_gv1b366rl2080000gp/T/test-16790a.o -lboost_serialization -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.1.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
<LINES ARE OMITTED>
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [install] Error 1

Building MongoDB with SSL RedHat fails: collect2: ld returned 1 exit status

Trying to build MongoDB with SSL on RHEL 6.4, I get the error
collect2: ld returned 1 exit status
Tried running the failed line with -v for g++ verbosity, in order to get some usefule information, but got no further information. All I get is:
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC)
COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/4.4.7/:/usr/libexec/gcc/x86_64-redhat-linux/4.4.7/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/4.4.7/:/usr/lib/gcc/x86_64-redhat-linux/:/usr/libexec/gcc/x86_64-redhat-linux/4.4.7/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/4.4.7/:/usr/lib/gcc/x86_64-redhat-linux/
LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/4.4.7/:/usr/lib/gcc/x86_64-redhat-linux/4.4.7/:/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-o' 'build/linux2/ssl/mongo/mongotop' '-fPIC' '-pthread' '-rdynamic' '-L/usr/lib64' '-L/lib64' '-shared-libgcc' '-mtune=generic'
...
...
build/linux2/ssl/third_party/yaml-cpp-0.5.1/src/singledocparser.o build/linux2/ssl/third_party/yaml-cpp-0.5.1/src/stream.o build/linux2/ssl/third_party/yaml-cpp-0.5.1/src/tag.o --end-group -lpthread -lssl -lcrypto -lrt -lstdc++ -lm -lgcc_s -lgcc -lpthread -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-redhat-linux/4.4.7/crtend.o /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crtn.o
(This one last "line" fills up ~2 screens, so I omitted most of it, leaving the beginning and end of it.
Next line is just the error: collect2: ld returned 1 exit status. Nothing more.
Any idea how to figure out this error?
Figures out package boost-devel was missing.

xcodebuild not finding gcc 4.2

I am trying to run xcodebuild and I am getting the following error:
2011-12-11 04:42:22.834 xcodebuild[9155:4203] error: Error Domain=NSPOSIXErrorDomain Code=2 "Non-zero exit code 127 returned from shell command: /Developer/Library/Xcode/PrivatePlugIns/Xcode3Core.ideplugin/Contents/Frameworks/DevToolsCore.framework/Resources/gcc-4.2 -v -E -dM -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk -x objective-c -c /dev/null 2>&1" UserInfo=0x4001a61a0 {NSLocalizedDescription=Non-zero exit code 127 returned from shell command: /Developer/Library/Xcode/PrivatePlugIns/Xcode3Core.ideplugin/Contents/Frameworks/DevToolsCore.framework/Resources/gcc-4.2 -v -E -dM -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk -x objective-c -c /dev/null 2>&1, NSLocalizedFailureReason=No such file or directory}
2011-12-11 04:42:22.835 xcodebuild[9155:4203] Warning: Couldn't discover the 'gcc-4.2' compiler's built-in search paths and preprocessor definitions for language dialect 'objective-c'.
Compiler: /Developer/Library/Xcode/PrivatePlugIns/Xcode3Core.ideplugin/Contents/Frameworks/DevToolsCore.framework/Resources/gcc-4.2
Reason: /Developer/Library/Xcode/PrivatePlugIns/Xcode3Core.ideplugin/Contents/Frameworks/DevToolsCore.framework/Resources/gcc-4.2 -v -E -dM -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk -x objective-c -c /dev/null 2>&1
2011-12-11 04:42:22.895 xcodebuild[9155:4203] error: Error Domain=NSPOSIXErrorDomain Code=2 "Non-zero exit code 127 returned from shell command: /Developer/Library/Xcode/PrivatePlugIns/Xcode3Core.ideplugin/Contents/Frameworks/DevToolsCore.framework/Resources/gcc-4.2 -v -E -dM -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk -x c -c /dev/null 2>&1" UserInfo=0x4013cbb80 {NSLocalizedDescription=Non-zero exit code 127 returned from shell command: /Developer/Library/Xcode/PrivatePlugIns/Xcode3Core.ideplugin/Contents/Frameworks/DevToolsCore.framework/Resources/gcc-4.2 -v -E -dM -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk -x c -c /dev/null 2>&1, NSLocalizedFailureReason=No such file or directory}
2011-12-11 04:42:22.900 xcodebuild[9155:4203] Warning: Couldn't discover the 'gcc-4.2' compiler's built-in search paths and preprocessor definitions for language dialect 'c'.
Compiler: /Developer/Library/Xcode/PrivatePlugIns/Xcode3Core.ideplugin/Contents/Frameworks/DevToolsCore.framework/Resources/gcc-4.2
Reason: /Developer/Library/Xcode/PrivatePlugIns/Xcode3Core.ideplugin/Contents/Frameworks/DevToolsCore.framework/Resources/gcc-4.2 -v -E -dM -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk -x c -c /dev/null 2>&1
Any idea why this is? I am guessing that it is because I don't have gcc-4.2 in the following path:
/Developer/Library/Xcode/PrivatePlugIns/Xcode3Core.ideplugin/Contents/Frameworks/DevToolsCore.framework/Resources/gcc-4.2
as of right now gcc-4.2 is located at usr/bin. The question is how do I redirect it?
This could be be related to your $CC variable in your shell ( it keeps track of your compiler ) you can find more information from jMoody on github
Essentially you need to remove $CC
How did you select the compiler? Go to the Xcode navigator, click on the upmost item, then in the right window on your project (not the target), then Build Settings. U and in the section Build Options you can select the compiler. Usually you can choose between LLVM gcc-4.x and some Apple LLVM x.
Have you used xcode-select to select the version of Xcode you want to use?
Manpage.