Exception handling in gcc compiler in AIX - aix

I am using AIX 7.1 and gcc 8.3 compiler. I see that exception thrown are not caught if I build with -Wl,-G flag. In the code below, if I do not use the -Wl,-G flag, I see "catch int". With this flag, program cores.
void foo()
{
try {
throw 1;
} catch(int&) {
std::cout << “catch int” << std::endl;
}
}
int main()
{
foo();
}
My guess is that exception handling is disabled by default and needs to get enabled by some compiler flag. Does anybody else have any experience with this? Please note this is specific to AIX platform.
This is how I am building. The entire code is in 1 file.
bare-08$ g++ -Wl,-G 1.cc
bare-08$ ./a.out
terminate called after throwing an instance of 'int'
IOT/Abort trap (core dumped)
bare-08$ g++ -Wl,-G -lsupc++ 1.cc
bare-08$ ./a.out
terminate called after throwing an instance of 'int'
terminate called recursively
IOT/Abort trap (core dumped)
Without -G option, I get linking error shown below (not in the toy program above, but in my real code).
ld: 0711-317 ERROR: Undefined symbol: .std::basic_istream >::seekg(long long, std::_Ios_Seekdir)
ld: 0711-317 ERROR: Undefined symbol: .sqrtf
ld: 0711-317 ERROR: Undefined symbol: std::basic_streambuf >::seekoff(long long, std::_Ios_Seekdir, std::_Ios_Openmode)
Has anyone seen this? I am in a rock and a hard place. Use -G option to get rid of the above linking error, but with that option, C++ exception handling does not work.

Don't use option -G. If you wish to use some AIX-specific option, use -brtl:
g++ -Wl,-brtl -o AmarnathShanbhag AmarnathShanbhag.cc && ./AmarnathShanbhag
catch int

Related

use cmake to build klee

I'm newer in using Linux and cmake.
I have some trouble when I want to build a KLEE system in ubuntu14.04.
When I come to the 8th part as the official page said. see in this page: http://klee.github.io/build-llvm34/
There is something wrong with the standard of c++ it uses -std=14 but I don't know why my compiler doesn't support it.
So my question is that: 1. is it necessary to use C++ 14? 2. and if is not how can I change the version the compiler used to avoid this kind of error?
llvm is 3.4
clang is 3.4
/home/codefiring/Desktop/software/klee/klee/tools/klee/main.cpp: In function ‘int main(int, char**, char**)’:
/home/codefiring/Desktop/software/klee/klee/tools/klee/main.cpp:1352:18: error: ‘put_time’ is not a member of ‘std’
<< std::put_time(std::localtime(&startTime), "%Y-%m-%d %H:%M:%S") << '\n';
^
/home/codefiring/Desktop/software/klee/klee/tools/klee/main.cpp:1460:16: error: ‘put_time’ is not a member of ‘std’
<< std::put_time(std::localtime(&endTime), "%Y-%m-%d %H:%M:%S") << '\n'
^
make[2]: *** [tools/klee/CMakeFiles/klee.dir/main.cpp.o] Error 1
make[1]: *** [tools/klee/CMakeFiles/klee.dir/all] Error 2
make: *** [all] Error 2

g++ doesn't recognize the file format of a dll

I am on Windows, and I am using the version of g++ that comes with mingw-64. I have a file on my computer called lua51.dll. When I try to run the following command :
g++ -shared -fPIC -o stuff.dll -llua51 stuff.cpp
I get the following error:
C:/Program Files/LOVE/lua51.dll: file not recognized: File format not recognized
collect2.exe: error: ld returned 1 exit status
make: *** [main] Error 1
How can I fix this? Please let me know if more information is needed; I am a complete beginner to compilation.
This is an issue you get when you try to include a 64-bit library when running a 32-bit version of g++ or even gcc.
I thought that that the version of g++.exe that comes with mingw-64 would produce 64-bit code, but it turns out this isn't true; it still only produces 32-bit code. In my case, lua51.dll is 64-bit, which is an issue since I was using the version of g++ that produces 32-bit code.
Instead, you need to use x86_64-w64-mingw32-g++.exe, which can be found in the same folder as g++.exe. This is the version of g++ that will produce 64-bit code.

Can't compile Fortran modules: Undefined symbol _main

I've been trying lately to use libraries in Fotran, but I kept on getting this error message
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
which I cound't find any specific solution to it. In this case, I was working with some libraries that I built myself (this problem happened with static and shared libraries) from simples modules I wrote for purposses of tests.
I decided to try only the modules then, and I kept getting the same error message regardes of the module I used. I would like to know if someone can help me on telling if I am using incorrect syntax. Here is the module
module modulo1
IMPLICIT NONE
real, parameter:: pi=3.1415
end module modulo1
This is the main
program teste
use modulo1
IMPLICIT NONE
real :: r = 2
write (*,*) 'Área: ', pi*r**2
end program teste
These were the commands I used for compiling
gfortran -c modulo1.f90
gfortran -c teste.f90
gfortran -o teste.o modulo1.o
Your compilation is broken. The command
gfortran -o teste.o modulo1.o
tells gfortran to create an executable called teste.o from the object file called modulo1.o. Since that module file doesn't contain a program the compiler can't find an entry point for the executable it is trying to build. The argument to the -o option is the name of the executable to build.
You probably ought to replace that statement with something like
gfortran -o test teste.o modulo1.o
which will build an executable called test.
In the longer run learn how to use make or another build system.

Linking LAPACK library with g++ on cygwin

Background
I am trying to find the eigenvalues of a complex matrix by using zgeev routine in LAPACK library. As far as I understand, LAPACK is written for FORTRAN and hence to use it with a C (or C++) program one has to make several modifications such as transforming the matrix and appending an underscore in the routine-name (REFERENCE:http://www.physics.orst.edu/~rubin/nacphy/lapack/codes/eigen-c.html)
Problem
To link LAPACK library to a C++ program (http://www.physics.orst.edu/~rubin/nacphy/lapack/codes/eigen-c.html)
and
compile it with g++ on cygwin on my windows 7 laptop, I am using the following command:
$ g++ eigen_complex.cpp -L G:\cygwin_root_dir\lib -lliblapack.a -llibblas.a
and getiing the following result:
eigen_complex.cpp: In function `int main()':
eigen_complex.cpp:41: error: `zgeev_' undeclared (first use this function)
eigen_complex.cpp:41: error: (Each undeclared identifier is reported only once for each function it appears in.)
I don't understand what is causing this error. Changing the name of the library from liblapack to lapack or to anything (say "lapa") does not make any difference to the error.
The following compiling commands return the same result as above
g++ eigen_complex.cpp -L G:\cygwin_root_dir\lib -llapack.a -lblas.a
g++ eigen_complex.cpp -L G:\cygwin_root_dir\lib -llapack -lblas
g++ eigen_complex.cpp -L G:\cygwin_root_dir\lib -lliblapack -llibblas
g++ eigen_complex.cpp -lliblapack -llibblas
and
g++ eigen_complex.cpp -lliblapack -lxyz
also.
I believe there is no library with name xyz and the compiler is not giving any warning about it.
Any help will be greatly appreciated.
Hopefully adding this prototype in a header somewhere in your project should resolve it:
extern "C" void zgeev_(char*, char*,int*,double *, int*, struct complex [], struct complex [1][1], int*, struct complex [1][1], int*, struct complex [], int*, struct complex [], int*);

Lapack undefined reference

I am new to g++ and lapack, and attempting to use them. I encountered a problem when I tried to compile the following naive code
#include <lapackpp.h>
int main()
{
LaGenMatDouble A;
return 0;
}
If I run the command
$g++ -L/usr/local/lib -llapackpp test2.cpp
where test2.cpp is the name of the cpp file, the terminal would give an error:
test2.cpp:1:22: fatal error: lapackpp.h: No such file or directory
But if I run the command:
$g++ -I/usr/local/include/lapackpp -L/usr/local/lib -llapackpp test2.cpp
the terminal would give an error:
/tmp/ccUi11DG.o: In function `main':
test2.cpp:(.text+0x12): undefined reference to `LaGenMatDouble::LaGenMatDouble()'
test2.cpp:(.text+0x23): undefined reference to `LaGenMatDouble::~LaGenMatDouble()'
collect2: ld returned 1 exit status
BTW, if I run the command
$pkg-config lapackpp --libs
the result is
-L/usr/local/lib -llapackpp
Could you please help me solve this? Thanks in advance!
Lapack requires fortran libraries, so that's where the -lgfortran comes from. Moreover, it appears the exact way to provide that library for the compiler depends on the Linux distriburion. From the documentation:
Requirements
This package requires the packages "blas", "lapack" (without the "++"), and a Fortran compiler. On most Linuxes these are available as pre-compiled binaries under the name "blas" and "lapack". For SuSE 10.x, the Fortran compiler is available as package "gfortran". For SuSE 9.x, the Fortran compiler is available as package "gcc-g77".
Not sure why pkg-config lapackpp --libs does not list -lgfortran
The -I/usr/local/include/lapackpp specifes the lapackpp-related header files. Without it the compiler cannot find lapackpp.h when you try to include it (#include <lapackpp.h>) -- see the compiler error in your question
I finally solved the problem but would still wonder why it has to be so.
The only command that can link cpp file to lapackpp library is:
g++ foo.cpp -o foo -lgfortran -llapackpp -I/usr/local/include/lapackpp
It would not work without -lgfortran, or with -I/usr/local/include/lapackpp replaced by -L/usr/local/lib.
Does anyone have an answer?