How can I see the full file path in compiler errors? - gcc

I have a CMake project that I compile with gcc on Linux. Because of how CMake invokes gcc in subdirectories, gcc outputs only the base file name when it encounters an error:
[100%] Building C object path/file.c.o
cd /absolute/path && /usr/bin/cc [...]
file.c: In function ‘foo’:
file.c:85:5: error: unknown type name ‘bar’
How can I see the full file path in the gcc output? Any solution through either CMake or gcc configuration would be acceptable. I want to see something like this:
/absolute/path/file.c:85:5: error: unknown type name ‘bar’
or
path/file.c:85:5: error: unknown type name ‘bar’
(preferrably the former).

I found the problem. Showing the full path should have been the default behaviour requiring no extra configuration. The compiler was showing only the file name because of a #line pre-processor directive in my source file.

Related

How to fix undefined reference LLVM error while linking CXX executable

I was trying to build a llvm-slicer from:
https://github.com/IAIK/ios-analysis-llvmslicer
and I follow the instructions:
cd llvm-slicer
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE="Release" -DLLVM_TARGETS_TO_BUILD="AArch64;X86" -DLLVM_ENABLE_EH=YES -DLLVM_ENABLE_RTTI=ON ..
make -j4 opt
make -j4 llvm-slicer
But when I execute the last command make -j4 llvm-slicer, I got an error:
[100%] Built target LLVMAnalysis
[100%] Linking CXX executable ../../bin/llvm-slicer
/usr/bin/ld: ../../lib/libLLVMSlicer.a(FunctionStaticSlicer.cpp.o): in function `llvm::Pass* llvm::callDefaultCtor<(anonymous namespace)::FunctionSlicer>()':
FunctionStaticSlicer.cpp:(.text._ZN4llvm15callDefaultCtorIN12_GLOBAL__N_114FunctionSlicerEEEPNS_4PassEv+0x1c): undefined reference to `vtable for (anonymous namespace)::FunctionSlicer'
collect2: error: ld returned 1 exit status
make[3]: *** [tools/llvm-slicer/CMakeFiles/llvm-slicer.dir/build.make:116: bin/llvm-slicer] Error 1
make[2]: *** [CMakeFiles/Makefile2:9647: tools/llvm-slicer/CMakeFiles/llvm-slicer.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:9654: tools/llvm-slicer/CMakeFiles/llvm-slicer.dir/rule] Error 2
make: *** [Makefile:2740: llvm-slicer] Error 2
I have no idea about how to fix it and I couldn't find any similar issues on Google, I hope someone can help me to figure it out, many thx.
There can be several scenarios for this issue, but in my opinion, here the scenario is for the given information that your default compiler (_ZN...something errors mostly because of compilers or linkers) is earlier version of gnu (gcc for c, g++ for c++) in your host pc (or maybe another compiler other than clang) and struggling about resolving a c++ feature anonymous namespace, as, a part of given error says:
/usr/bin/ld: ../../lib/libLLVMSlicer.a(FunctionStaticSlicer.cpp.o): in function `llvm::Pass* llvm::callDefaultCtor<(anonymous namespace)::FunctionSlicer>()':
FunctionStaticSlicer.cpp:(.text._ZN4llvm15callDefaultCtorIN12_GLOBAL__N_114FunctionSlicerEEEPNS_4PassEv+0x1c): undefined reference to `vtable for (anonymous namespace)::FunctionSlicer'
For this, there are several things you can do:
1-) You can change your compiler for building. In command window, you can export clang and clang++ as your compiler before cmake configuration. Here I assume that you installed new versions of clang compiler from anywhere, even github clone, I can give several examples here how to export and you can adapt one of them to your case easily:
export CC=clang
export CXX=clang++
another version:
export CC=clang-11
export CXX=clang++-11
another version:
export CC=/usr/bin/clang
export CXX=/usr/bin/clang++
another version:
export CC=/usr/bin/clang-12
export CXX=/usr/bin/clang++-12
another github clone version:
export CC=~/llvm/llvm-project/build/bin/clang
export CXX=~/llvm/llvm-project/build/bin/clang++
Even if this does not change your compiler, you can change your compiler while configuring with cmake by -DCMAKE_C_COMPILER={your-c-compiler} and -DCMAKE_CXX_COMPILER={your-c++-compiler} cmake flags. Try either with gcc or clang. Here is an example configuration in your case:
cmake \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_BUILD_TYPE="Release" \
-DLLVM_TARGETS_TO_BUILD="AArch64;X86" \
-DLLVM_ENABLE_EH=YES \
-DLLVM_ENABLE_RTTI=ON ..
2-) Error can be because of c++ standard, you can add -DCMAKE_CXX_STANDARD=14 (Default C++ standard using by LLVM) flag as cmake configuration like:
cmake -DCMAKE_BUILD_TYPE="Release" -DLLVM_TARGETS_TO_BUILD="AArch64;X86" -DLLVM_ENABLE_EH=YES -DLLVM_ENABLE_RTTI=ON -DCMAKE_CXX_STANDARD=14 ..
3-) Even if didn't work above cases, you can remove anonymous namespace from FunctionStaticSlicer.cpp file (given in the error message) and try to build again. You can find these lines like this:
// some code here and do not delete
namespace { // delete this line
// as you can see there is no name of namespace that's why called 'anonymous'
// if it was it would be like 'namespace nmspcName {'
// some code here and do not delete
} // and delete this line, too
// some code here and do not delete
But this is really bad practice, even if it can solve your problem, I do not recommend.
Also you can try to do similar changes in CMakeLists.txt file or adding other cmake configuration flags, however in my opinion, you could solve your problem easily by 1. option which is changing your default compiler.

Compiling superopt on windows

I'm triing to compile the superoptimizer on windows. (https://github.com/bonzini/superopt)
Unfortunatly my knowledge of make is very limited. I tried:
make CPU=-D386 superopt
Which gives me the error:
cc superopt.c -o superopt
process_begin: CreateProcess(NULL, cc superopt.c -o superopt, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [superopt] Fehler 2
After setting the compiler to gcc manually with:
make CPU=-D386 superopt CC=gcc
I get the following error:
gcc superopt.c -o superopt
In file included from superopt.c:27:0:
superopt.h:104:2: error: #error You have to choose target CPU type (--with-arch).
#error You have to choose target CPU type (--with-arch).
^
In file included from superopt.h:130:0,
from superopt.c:27:
longlong.h:1465:14: error: unknown type name 'UQItype'
extern const UQItype __clz_tab[];
^
superopt.c:32:21: fatal error: version.h: No such file or directory
compilation terminated.
make: *** [superopt] Fehler 1
It seems it does't properly selects i386.
Any hints would be greatly appreciated.
That is not the source code of
GNU superopt. It is the source code of someone's project
to patch GNU superopt, last updated 2008, and seemingly
abandoned a hard-hat area.
This is the source code of
GNU superopt. Extract the tarball and build as you have attempted
with:
make CC=gcc CPU=-DI386 superopt
Note: I386, not 386.
You will see warnings like:
warning: incompatible implicit declaration of built-in function 'foo'
because the 20 yearold C code does not diligently include the standard
headers that prototype the standard functions that it calls, but superopt will build successfully.

cross-compiling with gcc, got storage size of ... isn't known error when it is defined in an include file under sysroot

I have a question very simliar to Cross compiler default include path setup but there wasn't the answer I was looking for.
I built a cross-compiler for openrisc. I have it in ~/openrisck/toolchain/
under there, I have bin(or32-linux-* excutables are here), include, lib, lib64, libexec, or32-linux, share.
under or32-linux, I have bin, include, lib, sys-root.
When I build busybox, I gave CONFIG_CROSS_COMPILER_PREFIX as "or32-linux-".
and CONFIG_SYSROOT as "$SYSROOT" which is ~/openrisk/toolchain/or32-linux/sys-root.
then I run 'make install' in buxybox source. Since the path includes the cross-compiler directory, it compiles for or32-linux-. But I have an error below
ckim : srctree = /home/ckim/openrisc/busybox
CC applets/applets.o
In file included from /home/ckim/openrisc/toolchain/bin/../lib/gcc/or32-linux/4.5.1-or32-1.0rc1/include-fixed/syslimits.h:7:0,
from /home/ckim/openrisc/toolchain/bin/../lib/gcc/or32-linux/4.5.1-or32-1.0rc1/include-fixed/limits.h:34,
from include/platform.h:141,
from include/libbb.h:13,
from include/busybox.h:8,
from applets/applets.c:9:
/home/ckim/openrisc/toolchain/bin/../lib/gcc/or32-linux/4.5.1-or32-1.0rc1/include-fixed/limits.h:169:61: fatal error: limits.h: No such file or directory
compilation terminated.
make[1]: *** [applets/applets.o] Error 1
make: *** [applets_dir] Error 2
which makes me thinks that Ah! the cross-compiler uses the include path relative to the executable. (see above bin/../lib/gcc/or32-linux/version/include-fixed)
So the include limits.h goes to the gcc's limits.h correctly. The last file syslimits.h has #include_next when the limits.h file have already been included. and the compiler complains that the file cannot be found.
Can somebody tell me how to solve this problem? (limits.h includes syslimits.h and syslimits.h includes limits.h .. )
EDIT : I ran 'make CROSS_COMPILE=or32-linux- CONFIG_PREFIX=$SYSROOT install'
then I got 'lutimes undeclared in coreutil/touch.c' error. Assuming the limit.h problem is gone, this means I should give these command line arguments because CROSS_COMPILE for make is different from CONFIG_CROSS_COMPILER_PREFIX in busybox configuration and make's CONFIG_PREFIX is different from CONFIG_SYSROOT for busybox configuration. so to remove the lutimes error, I ran 'make menuconfig' and removed CONFIG_TOUCH. Then I reran the make(make CROSS_COMPILE=or32-linux- CONFIG_PREFIX=$SYSROOT install), and this time got
procps/free.c: In function 'free_main':
procps/free.c:51:17: error: storage size of 'info' isn't known
procps/free.c:77:2: warning: implicit declaration of function 'sysinfo'
I found that in $SYSROOT/usr/include/sys/sysinfo.h, struct sysinfo is defined. I don't know why it says it's not defined. Any help would be deeply appreciated. Thanks!
For anyone who might be facing the same problem I had..
I tried about 3 times with the old toolchain but failed.
Yesterday, I got help from IRC (openrisc) and someone told me there is an updated toolchain for or1k. (not or32 which is old. I should have read the opencore page first..)
The page is
http://opencores.org/or1k/OpenRISC_GNU_tool_chain#Linux_.28uClibc.29_toolchain_.28or1k-linux-uclibc.29 (read from Linux (uClibc) toolchain (or1k-linux-uclibc))

Trouble compiling FUSE filesystems on OS X

OS: OS X Mavericks (v10.9)
FUSE: OSXFUSE v2.6.2
I'm trying to compile the loopback filesystem in C, but I'm getting this error:
$ make
cc -D_FILE_OFFSET_BITS=64 -I/usr/local/include/osxfuse/fuse -Wall -g -F/Library/Frameworks -o loopback loopback.c -losxfuse
ld: library not found for -losxfuse
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [loopback] Error 1
Trying to compile boxfs2 also produces this error:
$ make
Package libxml-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libxml-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libxml-2.0' found
Package libcurl was not found in the pkg-config search path.
Perhaps you should add the directory containing `libcurl.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libcurl' found
Package libapp was not found in the pkg-config search path.
Perhaps you should add the directory containing `libapp.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libapp' found
Package libjson was not found in the pkg-config search path.
Perhaps you should add the directory containing `libjson.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libjson' found
Compiling boxfs.c
cc -c boxfs.c -o boxfs.o
boxfs.c:15:10: fatal error: 'fuse.h' file not found
#include <fuse.h>
^
1 error generated.
make: *** [boxfs.o] Error 1
Can anyone point me in the right direction?
As far as the first problem, you need the OSXFUSE library somewhere the compiler can see it, or you need to tell the compiler where it is.
You may have some success using mdfind to locate the osxfuse library file, then add -L/path/to/osxfuse to the compile/configure script to the makefile.
Similarly, the for the second, try making sure boxfs2 knows about the fuse header: Looks like adding -I/usr/local/include/osxfuse/fuse might do it.

Trying to compile with Codelite on OSX(Mountain Lion) gives missing headers

I am trying out some cross platform GUI environments and have am evaluating wxWidgets using codelite, but have gotten stuck at the very beginning.
I am very new at this, if its a stupid question please say so.
prerequisites are,
Using OSX Mountain Lion
Installed wxmac via home brew
Downloaded Codelite, created a wxWidgets Executable
I make a GUI project and try to install but get a bunch of missing header errors.
make[1]: wx-config: Command not found
g++ -c "xxxx/helloworld/main.cpp" -g -O0 -Wall -o ./Debug/main.o -I. -I.
g++ -c "xxxx/helloworld/MainFrame.cpp" -g -O0 -Wall -o ./Debug/MainFrame.o -I. -I.
In file included from xxxx/helloworld/MainFrame.h:3,
from xxxx/helloworld/MainFrame.cpp:1:
xxxx/helloworld/wxcrafter.h:4:25: error: wx/settings.h: No such file or directory
xxxx/helloworld/wxcrafter.h:5:27: xxxx/helloworld/main.cpp:1:20: error: wx/app.h: No such file or directory
xxxx/helloworld/main.cpp:2:22: error: wx/event.h: No such file or directory
In file included from xxxx/helloworld/MainFrame.h:3,
from xxxx/helloworld/main.cpp:3:
xxxx/helloworld/wxcrafter.h:4:25: error: wx/settings.h: No such file or directory
xxxx/helloworld/wxcrafter.h:5:27: error: wx/xrc/xmlres.h: No such file or directory
xxxx/helloworld/wxcrafter.h:6:27: error: wx/xrc/xh_bmp.h: No such file or directory
xxxx/helloworld/wxcrafter.h:7:22: error: wx/frame.h: No such file or directory
xxxx/helloworld/wxcrafter.h:8:22: error: wx/sizer.h: No such file or directory
xxxx/helloworld/wxcrafter.h:9:22: error: wx/panel.h: No such file or directory
xxxx/helloworld/wxcrafter.h:10:21: error: wx/menu.h: No such file or directory
xxxx/helloworld/wxcrafter.h:11:24: error: wx/toolbar.h: No such file or directory
xxxx/helloworld/main.cpp:4:22: error: wx/image.h: No such file or directory
In file included from xxxx/helloworld/MainFrame.h:3,
from xxxx/helloworld/main.cpp:3:
xxxx/helloworld/wxcrafter.h:14: error: expected class-name before '{' token
xxxx/helloworld/wxcrafter.h:16: error: ISO C++ forbids declaration of 'wxPanel' with no type
xxxx/helloworld/wxcrafter.h:16: error: expected ';' before '*' token
xxxx/helloworld/wxcrafter.h:17: error: ISO C++ forbids declaration of 'wxMenuBar' with no type
xxxx/helloworld/wxcrafter.h:17: error: expected ';' before '*' token
xxxx/helloworld/wxcrafter.h:18: error: ISO C++ forbids declaration of 'wxMenu' with no type
xxxx/helloworld/wxcrafter.h:18: error: expected ';' before '*' token
xxxx/helloworld/wxcrafter.h:19: error: ISO C++ forbids declaration of 'wxMenuItem' with no type
xxxx/helloworld/wxcrafter.h:19: error: expected ';' before '*' token
xxxx/helloworld/wxcrafter.h:20: error: ISO C++ forbids declaration of 'wxMenu' with no type
xxxx/helloworld/wxcrafter.h:20: error: expected ';' before '*' token
xxxx/helloworld/wxcrafter.h:21: error: ISO C++ forbids declaration of 'wxMenuItem' with no type
xxxx/helloworld/wxcrafter.h:21: error: expected ';' before '*' token
xxxx/helloworld/wxcrafter.h:22: error: ISO C++ forbids declaration of 'wxToolBar' with no type
xxxx/helloworld/wxcrafter.h:22: error: expected ';' before '*' token
xxxx/helloworld/wxcrafter.h:25: error: 'wxCommandEvent' has not been declared
xxxx/helloworld/wxcrafter.h:26: error: 'wxCommandEvent' has not been declared
xxxx/helloworld/wxcrafter.h:29: error: expected `)' before '*' token
xxxx/helloworld/wxcrafter.h: In member function 'virtual void MainFrameBaseClass::OnExit(int&)':
xxxx/helloworld/wxcrafter.h:25: error: request for member 'Skip' in 'event', which is of non-class type 'int'
xxxx/helloworld/wxcrafter.h: In member function 'virtual void MainFrameBaseClass::OnAbout(int&)':
xxxx/helloworld/wxcrafter.h:26: error: request for member 'Skip' in 'event', which is of non-class type 'int'
my guess would be to specify the folder that includes all of these, but am not sure where to find them.
Well to be honest I'm not sure if thats the right action at all, maybe I need to install or set something up, perhaps I shouldn't use homebrew and install by source
Added
Thanks to VZ. I got it working, had to change some of the build settings, as bellow
Settings>BuildSettings>gnu g++>Tools>PATH Environment Variables set to
/usr/local/bin:/usr/bin:/bin
Set all the Compiler, Linker, Shared Object Linker settings to absolute path, so change
g++
to
/usr/bin/g++
and so forth.
This surely changes per setup of the machine so it probably shouldn't be followed to the letter, but should get you started.
hope this helps.
The error you need to fix is the very first one:
make[1]: wx-config: Command not found
Make sure wx-config is in your path. Do not specify the include paths manually, this is not the right way to do it, you must use wx-config.
You probably would need to download wxWidgets source code distribution (2.9.4 from this page or latest source code from SVN), unpack it, build libs from the source code
./configure && make && sudo make install
then reboot and after that try to build the Codellite.

Resources