error: linking with `cc` failed: exit code: 1 - macos

I have a single .rs file. When I compile it by rustc test1.rs, I get an error:
error: linking with `cc` failed: exit code: 1
note: cc '-m64' '-L' '/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib' '-o' 'test1' 'test1.o' '-Wl,-force_load,/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib/libmorestack.a' '-Wl,-dead_strip' '-nodefaultlibs' '/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib/libstd-4e7c5e5c.rlib' '/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib/libcollections-4e7c5e5c.rlib' '/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib/libunicode-4e7c5e5c.rlib' '/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib/librand-4e7c5e5c.rlib' '/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib/liballoc-4e7c5e5c.rlib' '/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib/liblibc-4e7c5e5c.rlib' '/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib/libcore-4e7c5e5c.rlib' '-L' '/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib' '-L' '/Users/alex/Documents/projects/rust/.rust/lib/x86_64-apple-darwin' '-L' '/Users/alex/Documents/projects/rust/lib/x86_64-apple-darwin' '-lSystem' '-lpthread' '-lc' '-lm' '-lcompiler-rt'
note: ld: warning: directory not found for option '-L/Users/alex/Documents/projects/rust/.rust/lib/x86_64-apple-darwin'
ld: warning: directory not found for option '-L/Users/alex/Documents/projects/rust/lib/x86_64-apple-darwin'
ld: can't open output file for writing: test1, errno=21 for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: aborting due to previous error
$ rustc --version
rustc 1.0.0-dev
I've seen some topic related to this one but none of them helped me to solve the problem.

I was faced with three problems on Mac compiling Rust:
First: If you have any issue with writing files/dirs by ld just remove that files and try to recompile. I don't know why, but on Mac this issue happens time to time.
Second: If you have other ld errors (not about file access): try to add the following sections to your ~/.cargo/config (if you don't have this file feel free to create):
[target.x86_64-apple-darwin]
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
]
[target.aarch64-apple-darwin]
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
]
Third: Sometimes your Mac lack of some dev tools/dependencies. Install the most important of them automatically with the command:
xcode-select --install

From your command rustc test1.rs the compiler infers the name of the executable should be test1. The linker tries to open this file so it can write the executable but fails with errno=21 whose stringified version is "Is a directory".
This suggests you have a directory in your working directory called test1 which is causing a conflict.

if you have "note: /usr/bin/ld: cannot find -lsqlite3"
then install libsqlite3-dev: $ sudo apt install libsqlite3-dev
This works on Rust 1.53.0, Linux Mint 20.2(based on Ubuntu 20.04 LTS)

If you have a MacBook M1(x) with ARM processor you need to install rust from rustup https://sourabhbajaj.com/mac-setup/Rust/
When you run rustup-init, use the customize option to change aarch64-apple-darwin to x86_64-apple-darwin
Then you can add the following to .cargo/config.toml or .cargo/config (either is fine)
[target.x86_64-apple-darwin]
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
]
This solution was tested with Rust 1.54 and MacBook M1
I was able to do a cargo build --release and generate a dylib file from this tutorial https://www.youtube.com/watch?v=yqLD22sIYMo

My rust project stopped building after updating my MacOS so this command fixed it for me
xcode-select --install

I had the same issue recently and I found out this solution that worked for me:
https://www.docker.com/blog/cross-compiling-rust-code-for-multiple-architectures/
On Running Rust on aarch64 I found out that libc6-dev-arm64-cross is need in order to compile rust successfully on aarch64.

Related

Compiling xv6 code but giving the errors on assembly instruction

I am using Ubuntu 18.04.2 LTS under windows 10 by using "Windows subsystem for Linux." I am experiencing some issues with XV6.
I set up XV6 by using the command:
git clone git://pdos.csail.mit.edu/xv6/xv6.git
sudo apt-get install libc6-dev
chmod 700 -R xv6-riscv
But when I typed in make command, I having the following issue:
***
*** Error: Couldn't find an riscv64 version of GCC/binutils.
*** To turn off this error, run 'gmake TOOLPREFIX= ...'.
***
gcc -c -o kernel/entry.o kernel/entry.S
kernel/entry.S: Assembler messages:
kernel/entry.S:17: Error: no such instruction: `la sp,stack0'
kernel/entry.S:18: Error: no such instruction: `li a0,1024*4'
kernel/entry.S:19: Error: no such instruction: `csrr a1,mhartid'
kernel/entry.S:20: Error: no such instruction: `addi a1,a1,1'
kernel/entry.S:21: Error: too many memory references for `mul'
kernel/entry.S:22: Error: too many memory references for `add'
kernel/entry.S:26: Error: no such instruction: `j junk'
<builtin>: recipe for target 'kernel/entry.o' failed
make: *** [kernel/entry.o] Error 1
Can anyone help me with this? (I am using an x64 system)
you should check this link: https://pdos.csail.mit.edu/6.828/2019/tools.html
for me I am running ubuntu, so I compiled the toolchain myself and then it works
I was running MacOS and had the same error. I solved it by updating the ~/.bashrc with:
PATH=$PATH:/usr/local/opt/riscv-gnu-toolchain/bin
before sourcing it or open a new interactive session. Then make qemu under xv6-riscv just ran!
So I would suggest you go back and check if you've finished each step: install toolchain, update env vars, source, and make.
For Suse you can install cross-riscv64-gccX package, where X is the gcc version
Then use
TOOLPREFIX=/usr/bin/riscv64-suse-linux-
it worked for me

fatal error: Eigen/Core: No such file or directory compilation terminated

I recently change my OS to the last mint cinamon. Compiling one of the library I need (and that I used to used without problem), I get this message:
fatal error: Eigen/Core: No such file or directory compilation terminated.
I don't know what to do.
Thanks for the help.
Including directory /usr/local/include/eigen3/ solved this for me.
Like this, for example:
g++ -I/usr/local/include/eigen3/ CODE.cpp -o EXECUTABLE
Try to install eigen3 library,
on Ubuntu it would be
sudo apt-get install libeigen3-dev

OSX Sierra Tensorflow build error: ld: file not found: #rpath/CUDA.framework/Versions/A/CUDA

I have followed the instruction in:
https://gist.github.com/notilas/a30e29ce514970e821a34153c1e78b3f
But cannot complete it.
OSX: Sierra
Tensorflow version 1.1.0 (Google says v1.2 does not support OSX CUDA)
CUDA Tool kit : 8.0
CUDNN : 6.0
Xcode : 7.2.1
Anaconda : 4.2 (Python version 3.5)
Error Log:
ERROR: /Users/so041e/ml/tensorflow/tensorflow/python/BUILD:2534:1:
Linking of rule '//tensorflow/python:_pywrap_tensorflow_internal.so'
failed: link_dynamic_library.sh failed: error executing command
external/bazel_tools/tools/cpp/link_dynamic_library.sh no ignored
ignored ignored
external/local_config_cuda/crosstool/clang/bin/crosstool_wrapper_driver_is_not_gcc
-shared -o ... (remaining 455 argument(s) skipped): com.google.devtools.build.lib.shell.BadExitStatusException: Process
exited with status 1.
clang: warning: argument unused during compilation: '-pthread'
ld: file not found: #rpath/CUDA.framework/Versions/A/CUDA for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Target //tensorflow/tools/pip_package:build_pip_package failed to build
Use --verbose_failures to see the command lines of failed build steps.
[.bash_profile]
export PATH="/Users/so041e/anaconda/bin:$PATH"
export CUDA_HOME=/usr/local/cuda
export HOME=/Users/so041e
export PATH="$CUDA_HOME/bin:$PATH"
export DYLD_LIBRARY_PATH="/usr/local/cuda/lib:/Developer/NVIDIA/CUDA8.0/lib":$DYLD_LIBRARY_PATH
export LD_LIBRARY_PATH=$DYLD_LIBRARY_PATH
export PATH=$DYLD_LIBRARY_PATH:$PATH
export PATH="//anaconda/bin:$PATH"
Moved CUDNN lib and include to /user/local/cuda
sudo mv -v cuda/lib/libcudnn* /usr/local/cuda/lib
sudo mv -v cuda/include/cudnn.h /usr/local/cuda/include
Didn't use "vent" Just used single python 3.5 at this moment.
Tried both, but no difference.
bazel build --config=cuda --config=opt --action_env PATH --action_env LD_LIBRARY_PATH --action_env DYLD_LIBRARY_PATH //tensorflow/tools/pip_package:build_pip_package
bazel build --config=cuda //tensorflow/tools/pip_package:build_pip_package
This might be a bit late, but I had this exact same problem and I managed to fix it.
First, #rpath/CUDA.framework/Versions/A/CUDA is a dynamic library install name for libcuda.dylib, which is found in /usr/local/cuda/lib. So do
otool -l /usr/local/cuda/lib/libcuda.dylib
Check where you see #rpath/CUDA.framework/Versions/A/CUDA; on my system it was in the command LC_REEXPORT_DYLIB. From here, it seems dyld doesn't resolve the #rpath for the LC_REEXPORT_DYLIB command, only LC_LOAD*_DYLIB commands. Meaning, it looks for the literal path "#rpath/CUDA.framework/Versions/A/CUDA". So you're going to have to change that by doing
sudo install_name_tool -change #rpath/CUDA.framework/Versions/A/CUDA \
/Library/Frameworks/CUDA.framework/Versions/A/CUDA \
/usr/local/cuda/lib/libcuda.dylib
This should resolve your problem.
Now why your system (and mine) has this install name for libcuda.dylib? I have absolutely no clue.

Configuring wxWidgets for OS X 10.10

I am trying to build a program that relies on wxWidgets to run properly. I have the latest version of Xcode installed. I have tried building wxWidgets (both wxWidgets-3.0.2 and wxWidgets-2.9.4, the version originally used by the main program). However, in both cases, running the makefile for the main program gives the following error:
make: /Users/path to wxWidgets/wxWidgets-2.9.4/build-cocoa-release/utils/wxrc/wxrc: No such file or directory
As I understand it, I need to build wxrc to get my main program to build properly (I have tried this, but apparently some header files are missing). Is there any way to configure wxWidgets before this step that will automatically build wxrc as well? Or is that something I need to build separately? If it is separate, how would that be done?
I've pasted the code I originally used to configure wxWidgets below, with line breaks to make it easier to read:
../configure --with-osx_cocoa --with-macosx-version-min=10.7
--with-macosx-sdk=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk
--prefix="$(pwd)" --with-opengl CC=clang CXX=clang++ CXXFLAGS="-stdlib=libc++ -std=c++11"
OBJCXXFLAGS="-stdlib=libc++ -std=c++11" LDFLAGS=-stdlib=libc++
There is one error while building wxWidgets:
../src/osx/cocoa/utils.mm:250:28: error: cannot initialize a parameter of type 'id' with an lvalue of type
'wxNSAppController *'
[NSApp setDelegate:appcontroller];
When I go into the samples directory and enter "make", I get: ld: library not found for -lwx_osx_cocoau_xrc-2.9 clang: error: linker command failed with exit code 1 (use -v to see invocation) When entering "make" in demos, I get: ld: library not found for -lwx_osx_cocoau_core-2.9 clang: error: linker command failed with exit code 1 (use -v to see invocation)
If I missed any steps I should have taken before these (something with Xcode maybe?) please let me know. Thank you very much in advance.
Similar question. I have sugested a workaround proposed on a forum as follows: you can use --with-macosx-sdk=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/".

Error when compiling Glog

I got an issue when compiling glog by running 'make' after running './configure'
Then I got an error:
Undefined symbols for architecture x86_64:
"testing::internal::StrStreamToString(std::__1::basic_stringstream, std::__1::allocator >)", referenced from:
testing::internal::String testing::internal::StreamableToString(void const const&) in logging_unittest-logging_unittest.o
testing::internal::String testing::internal::StreamableToString(int const&) in logging_unittest-logging_unittest.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: * [logging_unittest] Error 1
I am using glog-0.3.3 on Mac OS X.
SO how can i turn of testing while compiling glog?
In another context, i installed glog and gflags by using Macport, then i run a small program. It will generate a error :
"ERROR: unknown command line flag 'logtostderr'"
I believe that's the problem with linking to gflags. So how can i fix it. Thanks
GLog needs GFlags compiled in the "google" namespace instead of the now default "gflags" namespace.
In order to set this namespace you must compile and install gflags from source and set the GFLAGS_NAMESPACE variable to "google".
Here are the steps I followed in Kubuntu 14.04 and should be similar to what you should do in Mac OSX. These will place the GFlags source in /usr/local/src and install the library in the /usr/local/lib&include directories. The last command (ldconfig) registers the library in the system.
cd /usr/local/src/
cp /path/to/downloaded/gflags-2.1.1.tar.gz .
sudo tar xzf gflags-2.1.1.tar.gz
cd /tmp
mkdir buildgflags
cd buildgflags
cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_SHARED_LIBS=ON \
-DGFLAGS_NAMESPACE=google -G"Unix Makefiles" /usr/local/src/gflags-2.1.1/
make
sudo make install
sudo ldconfig
Alternatively you can apply the following patch in the GLog source (attached in the last reply):
https://code.google.com/p/google-glog/issues/detail?id=194
It basically uses the namespace of gflags after the includes on the GLogs unit test source files like so:
#ifdef HAVE_LIB_GFLAGS
#include <gflags/gflags.h>
using namespace gflags;
#endif

Resources