MySQL Connector/C++ crashes with g++8.1.0 and C++17 - c++

I just started programming in C++ using Visual Studio 2017 and connected to my database. Everything worked fine so far. Then I wanted to use a c++17 feature and realized I needed to upgrade my compiler.
After upgrading my compiler to g++8.1.0 using this blog with these commands (and a lot of trial and error):
git clone https://bitbucket.org/sol_prog/raspberry-pi-gcc-binary.git
cd raspberry-pi-gcc-binary
tar xf gcc-8.1.0.tar.bz2
mv gcc-8.1.0 /usr/bin
cd ..
rm -r raspberry-pi-gcc-binary
rm /usr/bin/gcc
rm /usr/bin/g++
ln -s /usr/bin/gcc-8.1.0/bin/gcc-8.1.0 /usr/bin/gcc
ln -s /usr/bin/gcc-8.1.0/bin/g++-8.1.0 /usr/bin/g++
# After getting the error "GLIBCXX_3.4.21 not found" I did the following:
rm /usr/lib/arm-linux-gnueabihf/libstdc++.so.6
# I don't know if this (next line) was necessary
rm /usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.22
ln -s /usr/bin/gcc-8.1.0/lib/libstdc++.so.6.0.25 /usr/lib/arm-linux-gnueabihf/libstdc++.so.6
Now the program compiles, but when I excecute it, it crashes. When I switch to the old compiler (g++-4.9) it works again. Maybe the new compiler isn't properly installed. Instructions on how to install GCC-8 on Raspbian would be great.
This is basically the program:
#include<string>
#include<stdlib.h>
#include<iostream>
#include<exception>
#include<mysql_driver.h> //OR #include<cppconn/driver.h>
#include<mysql_connection.h> //OR #include<cppconn/connection.h>
sql::mysql::MySQL_Driver* driver; //OR sql::Driver*
sql::Connection* conn;
int main(const int argc, const char* argv[]) {
try {
driver = sql::mysql::get_driver_instance(); //OR get_driver_instance();
conn = driver->connect("tcp://127.0.0.1:3306", "root", "MY_PW");
conn->setSchema("MY_DB");
} catch (std::exception &e) {
//err("Failed to connect to the database.", e);
}
}
And this is the error I get in Visual studio:
Aborted (gdb) 1055-var-create - * "__size" (gdb)
1066-stack-select-frame 16 (gdb) 1067-var-create - * "argc" The thread
'LSTGA.out' (0x5cfa) has exited with code 0 (0x0). The program '' has
exited with code 0 (0x0).
And this is the error I get when running it directly via SSH:
* Error in `./LSTGA.out': munmap_chunk(): invalid pointer: 0x7ec3c50c *
Aborted
The call stack:
Additional information:
Previous compiler: gcc-4.9 / g++-4.9 (still present)
New compiler: gcc-8.1.0 / g++-8.1.0
Previous LIBSTDC++: 6.0.22 (Removed)
New LIBSTDC++: 6.0.25
Remote machine: Raspberry Pi 2b
Remote OS: Raspbian
Local OS: Windows 10
Visual studio Community 2017 15.8.8
Thanks in advance. -Minding

I found the issue here:
Even a small change in the compiler version can cause problems. If you obtain error messages that you suspect are related to binary incompatibilities, build Connector/C++ from source, using the same compiler and linker that you use to build and link your application.
So the solution is to build the MySQL Connector/C++ from source as described here.
I hope this helps.

Related

Gradle Cpp-Application not detecting gcc in windows

I am starting to get into c++ more and I have began learning gradle to use as the build too for it. I am using gradle's cpp-application plugin for compiling the code. However when I try to build it gradlew tells me that it can't detect gcc, my only installed compiler.
I have for the most part followed the guide on gradle's website (https://guides.gradle.org/building-cpp-executables/). That is where I came up with most of the code so far.
I have gcc from ming-w32 installed in my path correctly (I can run it from the command prompt and through make without any issues)
I am also using a gradlew install that was made with gradle 5.2.1
I am, for the most part, using the exact setup in the gradle guide.
apply plugin : 'cpp-application'
application {
baseName = "test"
}
^ /$Project/build.gradle
This is the command line output when i run gradlew assemble
* What went wrong:
Execution failed for task ':compileDebugCpp'.
> No tool chain is available to build C++ for host operating system 'Windows 10' architecture 'x86-64':
- Tool chain 'visualCpp' (Visual Studio):
- Could not locate a Visual Studio installation, using the command line tool, Windows registry or system path.
- Tool chain 'gcc' (GNU GCC):
- Could not determine GCC metadata: failed to execute gcc.exe -m64 -dM -E -v -.
- Tool chain 'clang' (Clang):
- Could not find C++ compiler 'clang++' in system path.
When I run the command that they say failed to execute in the same command prompt (gcc.exe -m64 -dM -E -v -.)
I do get output from gcc without any errors that I can see
If you are curious on what it outputs you can find it here
I would expect that the issue isn't with my cpp code because it isn't ever recognizing the compiler but it is fairly short so I might as well.
#include <iostream>
int main(int argc, char** argv) {
std::cout << "Hello World!!" << std::endl;
return 0;
}
^ /$Project/src/main/cpp/main.cpp
By default, Gradle tries to locate a tool chain that matches your system's architecture (x86_64), but you only have a 32-bit MinGW
A workaround is to explicitly configure a 32-bit target in your Gradle script:
application {
targetMachines = [ machines.windows.x86 ]
}

perf-events not showing StackTraces on debian 8 jessie

I am trying to profile a simple C program with perf-events on debian 8 jessie. I can see symbols but I am unable to get stacktraces. The same procedure generates good stacktraces on ubuntu 16.04.
I have installed linux-image-amd64-dbg and libc6-dbg.
I have confirmed that kernel config parameters include CONFIG_KALLSYMS=y
I have compiled the program with gcc -g3 -O0 hello.c to enable debug symbols.
I start profiling with the following command.
sudo perf record -g ./a.out
I generate a flame graph Flame Graph with the following command
sudo perf script | ~/code/FlameGraph/stackcollapse-perf.pl | \
~/code/FlameGraph/flamegraph.pl > perf-kernel.svg
This is the listing for hello.c which I am trying to profile
#include <stdio.h>
#include <unistd.h>
void do2() {
FILE* f = fopen("/dev/zero", "r");
int fd = fileno(f);
char buf[100];
while(1) {
read(fd, buf, sizeof(buf)/sizeof(buf[0]));
}
}
int main(void)
{
do2();
return 0;
}
This is the flame graph with debian jessie
This is the flame graph with ubuntu
Why are stack traces missing in debian jessie?
Thanks
Sharath
Managed to find the issue.
I had to enable CONFIG_FRAME_POINTER=y and recompile the kernel as per Brendan Gregg's perf site
It is unfortunate that the kernel shipping with Debian 8 does not have this enabled, which breaks perf

C++ Mingw32 CreateProcess() failed with error code 2: The system cannot find the file specified

I am just trying to run a basic program in notepad++ and mingw32. I have attempted multiple different thing but I continue to get.
Current directory: \\THEBOX\Users\jacks_000\Documents
C:\MinGW\mingw32\bin\g++.exe -g "testpgrm"
CreateProcess() failed with error code 2:
The system cannot find the file specified.
================ READY ================
When I run the nppexec I use the following
NPP_SAVE
CD $(CURRENT_DIRECTORY)
C:\MinGW\mingw32\bin\g++.exe -g "$(FILE_NAME)"
I have also tried:
NPP_SAVE
CD $(CURRENT_DIRECTORY)
C:\MinGW\bin\g++.exe -g "$(FILE_NAME)"
I am just using a basic test program:
#include <iostream>
using namespace std;
int main()
{
cout<<"Hi";
return 0;
}
I don't know if I will have issue running it in the command prompt if I save it this way or if I have done something wrong. I am running Windows 10 if that is a issue.
Current directory: \THEBOX\Users\jacks_000\Documents
I think it's because g++ can't access to a SMB share.
Try to compile the file locally.
The problem is with the location of "C:\MinGW\mingw32\bin\g++.exe". Where it is on your PC, and what is the actual filename, will depend on your installation.
For example, on my machine I have and old version in "C:\Program Files (x86)\CodeBlocks13_02\MinGW\bin\mingw32-g++.exe", but a newer installation in another folder.
So you need to find the executable name and location of the compiler. You won't need to use the top two lines, just "C:\Program Files (x86)\CodeBlocks13_02\MinGW\bin\mingw32-g++.exe -g test.c", for example.
I did this and it gave a result of :
C:\Program Files (x86)\CodeBlocks13_02\MinGW\bin\mingw32-g++.exe -g test.c
Process started >>>
<<< Process finished. (Exit code 0)
================ READY ================

"Operation not permitted" running hello world binary compiled w/ clang++ on El Capitan

Background
I created a simple Hello World C++ program:
#include <iostream>
using namespace std;
int main() {
cout << "Hello World!" << endl;
return 0;
}
And compiled it with clang++ like so (g++ points to clang++ on OS X apparently):
g++ helloworld-cpp.cpp
This produces an executable, a.out. Running it at the prompt causes bash to throw the error Operation not permitted, as shown:
$ ./a.out
-bash: ./a.out: Operation not permitted
Things I've Tried
Verifying the file has execute permissions, and no attributes or flags that would prevent it from running, using ls -leO:
-rwxr-xr-x 1 monarch staff - 15212 Jan 1 13:51 a.out
Disabling "System Integrity Protection" using csrutil disable from the Recovery OS terminal, rebooting, recompiling, and running a.out. The same error messages results.
Question
Are there any other restrictions that could prevent binaries I compile on Mac OS X from running?
Figured it out.
My code was on an encrypted sparseimage, which had the quarantined attribute set on it. I checked this by running mount like so (see attributes on /Volumes/work):
$ mount
/dev/disk0s2 on / (hfs, local, journaled)
/dev/disk2s2 on /Volumes/work (hfs, local, nodev, nosuid, journaled, noowners, quarantine, mounted by monarch)
The actual sparseimage is located in my home folder, titled work.sparseimage. I removed the quarantine attribute like so:
$ xattr -d com.apple.quarantine work_personal.sparseimage
I then unmounted (ejected) the image, then re-mounted it, recompiled the file and it executed without the error.
Special thanks to #Mark Setchell for asking me in the question's comments if noexec was set on the drive, and to everyone else for their suggestions.

Running Ubuntu Eclipse C++ Helloworld

I'm trying to run a Hello world C++ on Eclipse on Ubuntu 12.04. I installed g++ and wrote this code:
#include<vector>
#include<string>
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World" << endl;
return 0;
}
Compile output:
**** Build of configuration Debug for project TopCoder ****
make all
make: Nothing to be done for `all'.
**** Build Finished ****
Run output message:
Launching TopCoder has encountered a problem
Error starting process
Error starting process.
Exec_tty error:Cannot run program "/media/01CCE00FA6888D80/Achieve/Eclipse/TopCoder/Debug/TopCoder": Unknown reason
Exec_tty error:Cannot run program "/media/01CCE00FA6888D80/Achieve/Eclipse/TopCoder/Debug/TopCoder": Unknown reason
Exec_tty error:Cannot run program "/media/01CCE00FA6888D80/Achieve/Eclipse/TopCoder/Debug/TopCoder": Unknown reason
when I put the source code on ext4 drive it builds and run
I changed
proc /proc proc nodev,noexec,nosuid 0 0
in /etc/fstab to
proc /proc proc dev,exec,suid 0 0
But no usefulness.
You're tring to run an application from the /media/01CCE00FA6888D80 volume. Removable USB? The most likely culprit is noexec as an option to the default mount command line.
check if noexec is part of the options for mounting the filesystem using:
grep noexec /proc/mounts
if this results in output indicating that noexec is in effect for the file system then try:
sudo mount -o remount,exec /media/01CCE00FA6888D80
Also, if the removable volume is NTFS, your milage may vary.
Try to build it from the command line. Then you will know if the problem is involved with g++ or with eclipse. I guess you should change your compiler path somewhere in the eclipse, are you sure you have eclipse-cdt? THe easiest way to compile it is:
g++ yourfile.cpp
Your problem is that you're workspace is probably on a different drive than the one you installed ubuntu on
You are running you project over Linux . i had facing same issue when my project was in my E drive . i gave read -write permission but still that was not enough for me . The same error was keep coming when i was trying to run the project .
I have shifted my project in my Home folder ,gave permission and the project ran !! .
I believe there was a problem with some permission for LINUX C compiler .