I am trying to link two files, one complied with nasm from an assembly file and the other compiled with gcc from a C file, using a custom file. The command executed is this one:
ld -m elf_i386 -T link.ld -o kernel kasm.o kc.o
However, it returns this error:
ld: target elf12-i386 not found
I am running a Debian 3.16.39 i686
Related
I'm stumped on this.
I am using Ubuntu 18.04. I want link together an executable as a 32-bit program, for educational purposes.
My ld default search paths are all for the 64bit toolchain, so I think I need to invoke ld with additional library search paths since I want to link as 32bit. It can not find libc for some reason.
ld -mi386linux -L/lib/i386-linux-gnu/ -lc -o cc codechef.o -dynamic-linker /lib/i386-linux-gnu/ld-linux.so.2
This gives me the error ld: cannot find -lc
I have verified that libc.so.6 file does exist at /lib/i386-linux-gnu/libc.so.6
adding --verbose to my command reveals: attempt to open /lib/i386-linux-gnu//libc.a failed Why does my ubuntu installation not have this file but does have the .so?
I am using the davidva/gcc49 copr, on Fedora 27.
When I try to compile after running source /usr/bin/gcc49 as the copr webpage describes, I get this error:
/usr/bin/ld: cannot find -lgcc_s
After learning about how the flag -l works for gcc, I learned it is looking for library gcc_s. I found it in /opt/gcc-4.9.3/lib64/gcc/x86_64-fedoraunited-linux-gnu/lib64, which sounds like the right spot for it to be. Why is it not linking? Do I need to add a directory to a library path? If it's LDFLAGS, it's already there because of the file I sourced:
export LDFLAGS="-L/opt/gcc-$gver/$lib/gcc/$gcc_target_platform/$lib/"
What do I need to do to get gcc 4.9 on Fedora 27 to find its library file which is clearly in the LDFLAGS directory?
The problem is that the libgcc_s.so file is in the wrong directory! Just symlink to it in the 4.9.3 directory:
pushd /opt/gcc-4.9.3/lib64/gcc/x86_64-fedoraunited-linux-gnu/4.9.3
sudo cp -p ../lib64/libgcc_s.so.1 .
sudo ln -s libgcc_s.so.1 libgcc_s.so
popd
I guess the /opt/gcc-4.9.3/lib64/gcc/x86_64-fedoraunited-linux-gnu/lib64 directory was supposed to be included in any LDFLAGS parameter, and that might be a weakness of the build process I was using and not the gcc 4.9 package.
Putting this file and appropriately-named symlink in the 4.9.3 directory allows my build process to complete successfully.
Reference: https://bgstack15.wordpress.com/2018/02/01/gcc-4-9-for-fedora-27/
I compiled some codes in Matlab on a Linux system, and .mexa64 files has been generated, but in run time, I get the following error:
Invalid MEX-file '/*.mexa64': /matlab-8.5/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: version `CXXABI_1.3.8' not found.
i tried setting -rpath in make file by two following commands in matlab make file:
LDFLAGS="\$LDFLAGS -rpath=/usr/local/GNU/glibc-2.22/lib/"
LDFLAGS="\$LDFLAGS -dynamic-linker=/usr/local/GNU/glibc-2.22/lib/ld-linux-x86-64.so.2"
But, it cannot solve the problem.
This worked for my case:
Goto your matlab installation:
cd /usr/local/MATLAB/R2015a/sys/os/glnxa64
and rename these two files:
sudo mv libstdc++.so.6 libstdc++.so.6.orig
sudo mv libgcc_s.so.1 libgcc_s.so.1.orig
Using Ubuntu 14.04
Distributor ID: Ubuntu
Description: Ubuntu 14.04.3 LTS
Release: 14.04
Codename: trusty
and trying to compile a hello world Swift program.
print("Hello World!")
I have verified the download:
gpg --verify swift-2.2-SNAPSHOT-2015-12-10-a-ubuntu14.04.tar.gz.sig
gpg: Signature made Thu 10 Dec 2015 07:17:37 PM PST using RSA key ID 412B37AD
gpg: Good signature from "Swift Automatic Signing Key #1 <swift-infrastructure#swift.org>"
gpg: WARNING: This key is not certified with a trusted signature!
gpg: There is no indication that the signature belongs to the owner.
Primary key fingerprint: 7463 A81A 4B2E EA1B 551F FBCF D441 C977 412B 37AD
But when I try and compile the hello world program I get this error:
> swiftc hello_world.swift
<unknown>:0: error: opening import file for module 'SwiftShims': No such file or directory
If I start up the Swift REPL I get a similar error:
~$ swift
Welcome to Swift version 2.2-dev (LLVM 7bae82deaa, Clang 53d04af5ce, Swift 5995ef2acd). Type :help for assistance.
1> y = 6
opening import file for module 'SwiftShims': No such file or directory
1>
If I follow the instructions given here on using "swift build" versus "swiftc" for compiling a Hello World Swift program, I get a different error:
$ swift build
<unknown>:0: error: opening import file for module 'Swift': No such file or directory
swift-build: exit(1): ["/home/scooter/Programs/Swift/V2.2/bin/swiftc", "--driver-mode=swift", "-I", "/home/scooter/Programs/Swift/V2.2/lib/swift/pm", "-L", "/home/scooter/Programs/Swift/V2.2/lib/swift/pm", "-lPackageDescription", "/home/scooter/code/swift/helloworld-project/Package.swift"]
Executing the interpreter:
$ swift hello_world.swift
gives
<unknown>:0: error: opening import file for module 'SwiftShims': No such file or directory
strace gets an error trying to run swift:
$ strace -o /tmp/swift.log -- swift <(echo '1 + 1')
<unknown>:0: error: opening import file for module 'SwiftShims': No such file or directory
open("/home/user/Programs/Swift/V2.2/lib/swift/linux/x86_64/SwiftShims.swiftmodule",
O_RDONLY) = -1 ENOENT (No such file or directory)
Sorry for adding as an answer what should have really been a comment content-wise, but it is a little too long for a comment.
As far as I can tell, this is indeed the same problem as described in Swift on Linux: Make very first step work. I have been looking into this myself in my spare time, but no luck so far. The user who asked the other question has been pursuing it and has some interesting recent updates there.
A few things to try:
See if the swift interpreter works. Just type swift hello_world.swift and see what happens. I don't think it will work. If it does not, then run the strace command as follows:
strace -o /tmp/swift.log -- swift <(echo '1 + 1')
and look at /tmp/swift.log. See what files cannot be found, especially near the end of the output. Warning: even on a system where the error doesn't happen (I haven't been able to reproduce it yet), the strace output shows a lot of No such file... errors.
You can also try swift and swiftrc with the -v option to enable verbose output and see if you notice anything suspicious.
Update 1/2/2016:
The question referenced earlier has been updated with a possible solution to the problem: get rid of non-standard installations of gcc, g++, libgcc, and libstdc++. Please see the comments in the other question.
Update 1/3/2016:
Using the clues from the discussion on the other question, I've been able to reproduce the problem by installing gcc-5.1.0 from source and pre-pending the location of the newly-installed libstdc++.so.6 to the LD_LIBRARY_PATH variable.
The problem could be solved as follows:
1) Figure out where libstdc++.so.6 from the older package is installed. On my system:
user#ubuntu14:~$ dpkg -l | grep libstdc++
ii libstdc++-4.8-dev:amd64 4.8.4-2ubuntu1~14.04 amd64 GNU Standard C++ Library v3 (development files)
ii libstdc++6:amd64 4.8.4-2ubuntu1~14.04 amd64 GNU Standard C++ Library v3
user#ubuntu14:~$ dpkg -L libstdc++6 | grep libstdc++.so
/usr/share/gdb/auto-load/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19-gdb.py
/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19
/usr/lib/x86_64-linux-gnu/libstdc++.so.6
2) Prepend the location of libstdc++.so.6 to $LD_LIBRARY_PATH:
export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH
3) Double-check that the swift binary is using the correct shared library:
user#ubuntu14:~$ ldd `which swift` | grep libstdc++
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fdd1476b000)
Now Swift should work without the error in question.
Do you have a non standard install using a PPA or any libraries for the build chain built from source? Particularly libstdc++. Please see my answer for Swift on Linux: Make very first step work.
I am trying to compile a matlab program using mex. I am facing the following error and was wondering if you have any suggestions. I have installed latest version of mpfr at /usr/local/opt/mpfr but it is still picking /usr/local/opt/mpfr2.
The error is as below:
dyld: Library not loaded: /usr/local/opt/mpfr2/lib/libmpfr.1.dylib
Referenced from: /usr/local/Cellar/gcc48/4.8.1/gcc/libexec/gcc/x86_64-apple-darwin12.5.0/4.8.1/cc1plus
Reason: Incompatible library version: cc1plus requires version 4.0.0 or later, but libmpfr.1.dylib provides version 3.0.0
g++-4.8: internal compiler error: Trace/BPT trap: 5 (program cc1plus)
/Applications/MATLAB_R2012b.app/bin/mex: line 1326: 15075 Abort trap: 6 /usr/local/bin/g++-4.8 -c -I/Applications/MATLAB_R2012b.app/extern/include -I/Applications/MATLAB_R2012b.app/simulink/include -DMATLAB_MEX_FILE -fno-common -fexceptions -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/ -mmacosx-version-min=10.7 -DMX_COMPAT_32 -O2 -DNDEBUG "face-detection/src/resizef.cc" -o face-detection/private/resizef.o
Try running this command before compiling:
setenv('DYLD_LIBRARY_PATH','')
I was trying to compile something else (not a Matlab program) and received the same error. The same command worked in bash, so I inspected the environment variables and found that Matlab's DYLD_LIBRARY_PATH differed from bash's DYLD_LIBRARY_PATH. The bash DYLD_LIBRARY_PATH was not defined, so I set it to empty in Matlab and it fixed the path error.
Matlab's setenv documentation:
Values assigned to variables using setenv are picked up by any
process that is spawned using the MATLAB SYSTEM, UNIX, DOS or '!'
functions. You can retrieve any value set with setenv by using
GETENV(NAME).
Try reinstalling gcc and its mpfr2 package, e.g.:
brew reinstall gcc48 mpfr2
Also make sure you're not overriding any DYLD_LIBRARY_PATH, DYLD_FALLBACK_LIBRARY_PATH or DYLD_FRAMEWORK_PATH variables from the startup shell scripts (e.g. ~/.bash_profile).