Linker path not found - gcc

Currently I am working on GnuWin32 rpcgen tool on Windows 10. My files get compiled and I am able to generate .o files for client and server. But It fails in the linking process. I am running following makefile by make -f Makefile. I am using cygwin tool on windows.
# Compiler flags
CC = gcc
CFLAGS += -g
LDLIBS += -lnsl
RPCGENFLAGS =
I am getting following error:
gcc -g -o ipg_rpc_client ipg_rpc_clnt.o ipg_rpc_client.o ipg_rpc_xdr.o -lnsl
/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lnsl: No such file or directory
collect2: error: ld returned 1 exit status
make: *** [Makefile.ipg_rpc:41: ipg_rpc_client] Error 1
please help in solving this error. From last week I am struggling on this.

Finally the error got solved.
I have downloaded libtirpc-devel from cygwin, and changed my LDLIBS in makefile to -ltirpc.
Now my exes got created.

Related

Error in make cdec

I am trying to implement text generator of JAMR. It redirects me to install cdec. I followed this tutorial to install cdec. BUT
I installed gcc-4.8 (I had a better version 5.x but I thought 4.8 is neccessary). So I installed gcc-4.8 using this. And I build Boost using this (in ~/prefix/sw), I used boost_1_58 because it was latest. Everything worked fine.
Coming back to the tutorial, instead of cd ~/prefix/sw I went to cd jamr/tools/cdec where my cdec is present. Did autoreconf -ifv and ./configure --prefix=/home/student/prefix, fine till now (I just had to comment line 216 of containing boost_major_version and wrote boost_major_version="158"). But when I do make after a while I get
libtool: link: g++ -std=gnu++11 -fPIC -g -O3 /usr/lib /usr/lib -o reconstruct_weights reconstruct_weights.o -L/usr/lib libutils.a -ldl -lrt -lboost_program_options -lboost_regex -lboost_serialization -lboost_system -lboost_filesystem -lz -lbz2
/usr/bin/ld: cannot find /usr/lib: File format not recognized
/usr/bin/ld: cannot find /usr/lib: File format not recognized
collect2: error: ld returned 1 exit status
Makefile:836: recipe for target 'reconstruct_weights' failed
make[2]: *** [reconstruct_weights] Error 1
make[2]: Leaving directory '/home/student/ATS/jamr/tools/cdec-2014-10-12/utils'
Makefile:480: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/home/student/ATS/jamr/tools/cdec-2014-10-12'
Makefile:410: recipe for target 'all' failed
make: *** [all] Error 2
I tried sudo make, simple ./configure and make clean;make. No help. This is make file.
When you are in the cdec folder and you try to execute the commands there according to the instructions, we see that you get the collect2 error: error: ld returned 1 exit status. In the cdec folder, i initially execute the command:
gcc -std=gnu99 -Wall -Werror -g array_product.c -o array_product -I../../ZDK -L../../ZDK -I../../TestLib04 -L../../TestLib04 -ltestlib04 -lzdk -lncurses -lm
After this command, the error is solved and i get to the file and it says:
> First, you need all the build dependencies, and the fastest way to install them all is this command, which installs not only the compiler but the additional boost libraries and Flex that you'll need. sudo apt-get install build-essential libboost-all-dev cmake flex
> Secondly, create a directory and go into it (you said ~/prefix/sw in your comments).
> Thirdly, git clone https://github.com/redpony/cdec.git
> Fourthly, you probably did not read the README page on the GitHub repository which explains what commands to run to make the software build. It lists these as the build steps, after cd-ing into the newly created cdec folder.

Error in linking while creating a shared library of AES C file [duplicate]

This question already has answers here:
Linking OpenSSL libraries to a program
(4 answers)
Closed 5 years ago.
Encountering error while creating a shared library of AES. The following commands are used :
gcc -Wall Test1.c x64/libSESDAPI.a -fPIC -lssl -lcrypto
gcc -shared -o libfile.so a.out -nostartfiles
And I am getting the following errors:
/usr/bin/ld: error in a.out(.eh_frame); no .eh_frame_hdr table will be created.
/usr/bin/ld: libfile.so: No symbol version section for versioned symbol `AES_cbc_encrypt##OPENSSL_1.0.0'
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
I am new to shared libraries so please help.
Edit: I have edited and added the lcrypto and lssl
Edit2: By adding a -c in the first command, the above errors are now resolved. But now accessing the .so file with python gives a new error
OSError: ./libfile.so: undefined symbol: SDSCListDevs
Please tell why this error is coming.
You should be creating your shared library from an object file, not from an executable program.
You also need to link with the SSL libraries.
Commands to use:
# Compile the source file, generate object file
gcc -Wall Test1.c -c -fPIC
# Link object file with libraries to create the shared object
gcc -shared -fPIC -o libfile.so Test1.o x64/libSESDAPI.a -lssl -lcrypto

RcppArmadillo Compile Errors on OS X Mavericks

This is a follow-up to the question at Element-Wise Matrix Multiplication in Rcpp
I have been getting a number of different kinds of errors with RcppArmadillo since upgrading to Mavericks. I have Xcode 5.0.2 and Command Line Tools installed. Also, gfortran from Homebrew. But I keep encountering the error below --
> cppFunction("arma::mat schur(arma::mat& a, arma::mat& b)
{ return(a % b); }", depends="RcppArmadillo")
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [sourceCpp_18474.so] Error 1
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include - I"/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.0/Resources/library/RcppArmadillo/include" -fPIC "-mtune=native -g -O2 -Wall -pedantic -Wconversion" -c fileaf992bfb8f84.cpp -o fileaf992bfb8f84.o clang++ -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/lib -L/usr/local/lib -o sourceCpp_18474.so fileaf992bfb8f84.o -L/Library/Frameworks/R.framework/Resources/lib -lRlapack -L/Library/Frameworks/R.framework/Resources/lib -lRblas -lgfortran /Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/lib/libRcpp.a -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
Error in sourceCpp(code = code, env = env, rebuild = rebuild, showOutput = showOutput, :
Error 1 occurred building shared library.
WARNING: The tools required to build C++ code for R were not found.
Please install Command Line Tools for XCode (or equivalent).
# Contents of Makevars
$ cat ~/.R/Makevars
CC=clang
CXX=clang++
CXXFLAGS="-mtune=native -g -O2 -Wall -pedantic -Wconversion"
FLIBS=-lgfortran
Commenting FLIBS=-lgfortran does not help and results in even more error messages --
> cppFunction("arma::mat schur(arma::mat& a, arma::mat& b) { return(a % b); }", depends="RcppArmadillo")
ld: warning: directory not found for option '-L/usr/local/lib/gcc/i686-apple-darwin8/4.2.3/x86_64'
ld: warning: directory not found for option '-L/usr/local/lib/x86_64'
ld: warning: directory not found for option '-L/usr/local/lib/gcc/i686-apple-darwin8/4.2.3'
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [sourceCpp_50381.so] Error 1
Thanks in advance.
Update
Following suggestions from response from Kevin and Dirk below, I re-installed Rcpp, RcppArmadillo and inline from source and updated FLIBS to point to the actual directory. This solved the issue.
# Update FLIBS in ~/.R/Makevars
FLIBS=-L/usr/local/Cellar/gfortran/4.8.2/gfortran
#Re-Install from source
install.packages(c("Rcpp","RcppArmadillo","inline"),type="source")
#Restart R
EDIT: If you're a Homebrew user, you now instead need to use brew install gcc (gfortran is no longer provided separate of gcc), and you can then follow the instructions here to get set up.
You have to symlink the libraries to /usr/local/lib manually:
ln -s /usr/local/Cellar/gfortran/4.8.2/gfortran/lib/libgfortran.* /usr/local/lib/
I thought brew link gfortran would handle this, but apparently it only symlinks the gfortran program and not the actual libraries. So, unfortunately, you have to do it yourself.
(Replace 4.8.2 with whichever version of gfortran you're using from homebrew.)
Alternatively, if you want to keep from modifying /usr/local/lib, you can use
FLIBS=-L/usr/local/Cellar/gfortran/4.8.2/gfortran
in your ~/.R/Makevars file instead, so R knows where to find the gfortran libraries.
I can only suggest you study the numerous threads on the r-sig-mac list, the different answers here on SO as well as the posts on the rcpp-devel list.
As your error comes from the failed Fortran linking, maybe also review the standard page by Simon U. as well as the tools page it points too. AFAIK you should use the (older) gfortran 4.2.* from that page with R -- but then I am not an OS X user.
Edit in late 2016: We now have more detailed instructions in section 2.16 of the Rcpp FAQ.

Building gperf from source

I'm trying to build gperf(Google's profiler) from source. During build process the following error comes up :
src/stacktrace_config.h:58:5: error: #error Cannnot calculate stack trace: need either libunwind or frame-pointers (see INSTALL file)
src/stacktrace.cc:109:3: error: #error Cannot calculate stack trace: will need to write for your environment
make: *** [stacktrace.lo] Error 1
So it seems i need libunwind.
1) I got the library from savannah's git repo.
2) Installed it in /opt/unwind.
3) I also added /opt/unwind/lib/pkgconfig to my PKG_CONFIG_PATH.
4) I edited libunwind.pc so that both pkg-config --cflags --libs libunwind comes up with correct values.
5) I added a libunwind.conf in /etc/ld.so.conf.d/ pointing to /opt/unwind/lib.
After all of these i've rerun ./configure in gperf root directory.
The config.log reads following :
configure:15852: checking libunwind.h usability
configure:15852: gcc -c -g -O2 conftest.c >&5
conftest.c:67:23: fatal error: libunwind.h: No such file or directory
compilation terminated.
configure:15852: result: no
<***snip****>
configure:15852: checking libunwind.h presence
configure:15852: gcc -E conftest.c
conftest.c:34:23: fatal error: libunwind.h: No such file or directory
compilation terminated.
<***snip***>
ac_cv_header_libunwind_h=no
So it seems It still does not know where libunwind is.
Then i tried to set environment variables with CFLAGS and LDFLAGS like following :
arif#khost:~/src/gperf$ CFLAGS=`pkg-config --cflags libunwind` LDFLAGS=`pkg-config --libs libunwind` ./configure
Now config.log seems more puzzling :
configure:15852: checking libunwind.h usability
configure:15852: gcc -c -I/opt/unwind/include conftest.c >&5
configure:15852: $? = 0
configure:15852: result: yes
configure:15852: checking libunwind.h presence
configure:15852: gcc -E conftest.c
conftest.c:34:23: fatal error: libunwind.h: No such file or directory
compilation terminated.
It reports first that there is libunwind.h but later it cant find it.
config.log also has this curious entry :
configure:15852: WARNING: libunwind.h: accepted by the compiler, rejected b y the preprocessor!
configure:15852: WARNING: libunwind.h: proceeding with the compiler's result
Also its putting up ac_cv_header_libunwind_h=yes
If i do make here it stops with the following error:
In file included from src/stacktrace.cc:65:0:
src/stacktrace_libunwind-inl.h:46:23: fatal error: libunwind.h: No such file or directory
compilation terminated.
make: *** [stacktrace.lo] Error 1
You need the libunwind headers too. Install the libunwind-devel package or equivalent.
Similar to bwzhou's answer, I tried following the answers in this SO question:
How to add include and lib paths to configure/make cycle?
and was able to finally get past the fatal error: libunwind.h: No such file or directory error when compiling gperftools with libunwind-1.2.1 compiled beforehand. More specifically, I set CPPFLAGS and LDFLAGS using the commands:
export CPPFLAGS='-I'$MY_INSTALL_DIR'/include '$CPPFLAGS
export LDFLAGS='-L'$MY_INSTALL_DIR'/lib '$CPPFLAGS
prior to executing ./configure --prefix=$MY_INSTALL_DIR, where $MY_INSTALL_DIR is my personal, non-standard directory in which I have to install software in the HPC cluster I work with due to lacking adequate permissions. After doing this, I was able to successfully execute make; make install. I hope this is helpful.
Try CPPFLAGS instead of CFLAGS when you invoke configure.

Why does my flex/yacc compiler not compile correctly on another linux machine

On my machine (Windows running cygwin) it compiles correctly. Flex is version 2.5.35 and bison is version 2.3
On linux machine 1 it compiles correctly. Flex is version 2.5.4 and bison is version 1.875c.
On linux machine 2 it does not compile correctly. Flex is version 2.5.4 and bison is 2.3.
One would expect by looking at the flex/bison version numbers that if it compiled correctly on my machine, it would compile correctly on machine 2, but that's not the case.
On linux machine 2, when I run gcc -c y.tab.c I get the following warnings several times
warning: incompatible implicit declaration of built-in function 'printf'
And when I run the following
gcc -o cminus y.tab.o lex.yy.o -ly -lfl
I get the following error.
gcc -o cminus y.tab.o lex.yy.o -ly -lfl
/usr/bin/ld: cannot find -ly
collect2: ld returned 1 exit status
make: *** [cminus] Error 1
This error can be removed by taking out the -ly option in gcc so that the program compiles, but the compiled program does not function correctly as it does on my machine and the other linux machine.
What could be causing the problem?
/usr/bin/ld: cannot find -ly
is the message you get when the linker cannot find the library.
You need to locate liby.a or liby.so and then insert a -L<that path> in your gcc command line.
On my Cygwin install, it's located in /lib/liby.a so I would use something like:
gcc -o cminus y.tab.o lex.yy.o -L /lib -ly -lfl
The warning sounds like you have a missing '#include ' in some source file. The link error means that you don't have liby.a installed on your machine. liby is part of yacc and some versions of bison, but is rarely actually needed (it just defines default implementations of yyerror and a couple other things). The fact that it links without it means that you don't really need it.
You don't say in what way the progrma misbehaves when its not functioning correctly, so that's tough to diagnose

Resources