I saw -L/home/kgbook/tools/libiconv/lib -liconv -R/home/kgbook/tools/libiconv/lib when make VERBOSE=1.
What's the meaning of -R, I saw nothing when gcc --help or man gcc. No -R option or argument, neither gcc nor g++.
And why we need -R/home/kgbook/tools/libiconv/lib after -L/home/kgbook/tools/libiconv/lib -liconv?
I'm still confused after saw the question
Where should I insert "etags -R ." in makefile?.
Related
This question already has answers here:
How to strip trailing whitespace in CMake variable?
(4 answers)
Closed 11 months ago.
I want to add libpqxx library to my project, but find_package doesn't seem work with it. So I decided to manually add pkg-config's output on libpqxx to compiler and linker flags. For some reason this doesn't work (I tried building with CLion and from terminal, they both failed but with different errors). But if I simply insert pkg-config's output manually, then everything works fine.
execute_process (COMMAND bash -c "pkg-config --cflags libpqxx" OUTPUT_VARIABLE libs_cflags)
execute_process (COMMAND bash -c "pkg-config --libs libpqxx" OUTPUT_VARIABLE libs_linker_flags)
# Prints 'flags ='
execute_process (COMMAND bash -c "echo flags = ${CMAKE_CXX_FLAGS}")
# Works fine
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/opt/homebrew/Cellar/libpqxx/7.7.0/include")
# Doesn't work
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${libs_cflags}")
# Prints 'flags=-I/opt/homebrew/Cellar/libpqxx/7.7.0/include'
execute_process (COMMAND bash -c "echo flags = ${CMAKE_CXX_FLAGS}")
# Works fine
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/opt/homebrew/Cellar/libpqxx/7.7.0/lib -lpqxx")
# Doesn't work
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${libs_linker_flags}")
Turns out libs_cflags and libs_linker_flags had trailing whitespaces. Using OUTPUT_STRIP_TRAILING_WHITESPACE for execute_process() solves the problem.
Can someone let me know what these two flags do in this makefile? I've googled 'till my fingures hurt, but cannot find any info. The GNU documentation doesn't seem have this info.
Thanks!
(-ln) and (-fs)
$(MAKE) -C wiringPi $#
$(MAKE) -C devLib $#
-ln -fs libwiringPiDev.so.2.0 devLib/libwiringPiDev.so
-ln -fs libwiringPi.so.2.0 wiringPi/libwiringPi.so
$(MAKE) -C gpio 'INCLUDE=-I../devLib -I../wiringPi' 'LDFLAGS=-L../devLib -L../wiringPi' $#
The ln -fs foo bar command creates a link named bar pointing to file foo. The -f option forces the creation: if a bar already exists it is overwritten (except if it is a directory). The -s option tells ln to create a symbolic link instead of the default hard link. See man ln to know more about this command.
The - on front of the command tells make that it should not abort if the command fails. If you are using GNU make see the make manual section about errors in recipes.
Thanks Eugene. Without the '-' I was able to find more info.
So I think the ln with the (-fs) is checking, then removing a existing file (if there is one) then making a symbolic link. cool.
I'm sure this was / is obvious to the experienced out there.
Thanks,
oc.
While following the tutorial on the Chisel official website for installation, I came to the point where I should test if the installation was done correctly. Doing so yields this error:
set -e -o pipefail; "sbt" -Dsbt.log.noformat=true -DchiselVersion="2.+" "run Parity --genHarness --compile --test --backend c --vcd --targetDir /home/me/chisel-tutorial/generated/examples " | tee /home/me/chisel-tutorial/generated/examples/Parity.out
/bin/bash: sbt: command not found
make: *** [/home/me/chisel-tutorial/generated/examples/Parity.out] Error 127
There is another question regarding the same problem here, where the suggestion to add SHELL=/bin/bash to the Makefile is made. That did not work for me. Another suggestion is to remove set -e -o pipefail: this suggestion actually works but is it OK to remove that option? what does it do?
Edit_1:
I have installed sbt and added its path to the PATH variable.
$ which sbt
/usr/bin/sbt
But still I am getting this error when running make Parity.out
set -e -o pipefail; "sbt" -Dsbt.log.noformat=true -DchiselVersion="2.+" "run Parity --genHarness --compile --test --backend c --vcd --targetDir /home/me/chisel-tutorial/generated/examples " | tee /home/me/chisel-tutorial/generated/examples/Parity.out
/bin/sh: 1: set: Illegal option -o pipefail
make: *** [/home/me/chisel-tutorial/generated/examples/Parity.out] Error 2
If I edit this part of the file suffix.mk:
$(objdir)/%.dot: %.scala
set -e -o pipefail; "$(SBT)" $(SBT_FLAGS) "run $(notdir $(basename $<)) --backend dot --targetDir $(objdir) $(CHISEL_FLAGS)"
$(objdir)/%.out: %.scala
set -e -o pipefail; "$(SBT)" $(SBT_FLAGS) "run $(notdir $(basename $<)) --genHarness --compile --test --backend c --vcd --targetDir $(objdir) $(CHISEL_FLAGS)" | tee $#
By deleting the -o option in the set -e -o pipefail it works, I get the PASSED and [success] message after running $ make Parity.out. So what is going on?
Edit_2:
It is working fine now after I added the SHELL=/bin/bash to the Makefile, so it was first a problem of not having sbt as Nathaniel pointed out then editing the Makefile to include SHELL=/bin/bash.
set -e -o pipefail is a way of making sure that the execution of the bash script both works as expected and that if there is a failure, it halts immediately (rather than at some later stage). Removing it might work - but if there is a failure it might get swallowed and hide the fact it's broken.
But I think your problem lies here, making the other question a bit of a red herring:
/bin/bash: sbt: command not found
Do you have sbt installed on your system? Run which sbt as the user that executes the script. For instance, on my system:
$ which sbt
/opt/local/bin/sbt
If you don't have it on your system, nothing will be returned by running which.
The script clearly needs access to sbt and is failing when it doesn't find it. If you do have it on your system, then there is a mismatch between the user running the script and access to that file. You'll need to post more information about how you're executing the script: in that case it is likely you'll have to update your PATH variables to be able to find the sbt executable.
Given that, after fixing this, you still have a problem, you have to ensure that you're running in bash, and not another terminal type. The reason for this is that bash supports set -o pipefail but a lot of other terminals don't. We suspect this might be the case because of the error messages:
/bin/sh: 1: set: Illegal option -o pipefail
Here we see that /bin/sh (the shell) is being invoked by the program. Use ls -l /bin/sh to determine if your /bin/sh is pointing to a particular shell. If it is not pointed to a bash shell, then you either need to repoint it (be careful! this is probably another question in it's own right), or need to specify to your Scala program to use a specific shell.
The -l option tells the linker to search the libraries in the standard dirs.
And with -L, we can specify our own library directories for searching.
Question: Does the sequence of order matters for the -L option too, like it does for the -l w.r.t the linker?
This link: http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html doesn't say much about the sequence of -L.
EDIT
Also,
Directories specified on the command
line are searched before the default
directories
is from the man page (as pointed by Dmitry), does this mean that even if I specify the order like:
gcc -lm hello.c -Lx
still the directory specified with -L will be given preference first?
Yes, the order of -L options matters - just like -l and -I options.
From man ld
-Lsearchdir
--library-path=searchdir
Add path searchdir to the list of paths that ld will search for archive libraries and ld control scripts. You may use this option any number of times. The directories are searched in the order in which they are specified on the command line. Directories specified on the command line are searched before the default directories. All -L options apply to all -l options, regardless of the order in which the options appear.
GCC documentations and more specifically Linking Options will be useful for you
Edit
Sorry, indeed I missed to check the link you've given. "man ld" can just be written in the console.
Edit2
I made a simple test putting -l before -L options and it shows no difference comparing to -L before -l
So answering your second question, this
gcc -lm hello.c -Lx
is equal to this
gcc -Lx -lm hello.c
libm is searched first in directory x/ in both tests.
Note though that putting -l<lib> before source files is a bad practice, that may lead to undefined references when linking. This is the correct way
gcc hello.c -Lx -lm
Is there a way to make gcc use the absolute path when printing errors found in files compiled in the current directory?
For instance the following does what I want when print errors:
g++ -I. -I../../.. /home/some/path/somefile.cpp
but I want to achieve the same with something like:
g++ -I. -I../../.. somefile.cpp
I want warnings and errors to be formatting something like:
/home/some/path/somefile.cpp:299:52: warning: some warning
There is no way to do this with gcc itself, but it's trivial with a wrapper script, installed as "gcc", "g++", etc in a directory before /usr/bin in your PATH:
#! /bin/sh
sourcefile="$1"; shift
case "$sourcefile" in
/*) ;;
*) sourcefile="$PWD/$sourcefile" ;;
esac
exec "/usr/bin/${0##*/}" "$sourcefile" "$#"
... provided that you always put the source file first in your compiler invocation (you'll have to tweak your Makefiles).