Cannot enable pthreads for Netbeans - c++

When I try to use the c++11 thread library in Netbeans (g++ 4.8.2 ubuntu 14.04 LTS) I get the following error:
##Failure Location unknown## : Error
Test name: Array2DTest::testArray2D
uncaught exception of type std::system_error
- Enable multithreading to use std::thread: Operation not permitted
I tried enabling pthreads by adding -pthread as a additional option for the compilation line as suggested by similar questions and the output seems to show the option is getting passed:
I've also tried compiling simple "hello world" type tests directly from the terminal and they actually work! For some reason I just can't get netbeans to enable it. The only thing I can think of is I'm trying to test out some multithreading functions in a cppunit test so is it possible this is messing up the pthread option?
EDIT: I found that taking out pkg-config --libs opencv results in the -pthreads switch working correctly, but I still cant figure out how to get both of them working correctly together.
EDIT2: I was able to get it to compile by removing the -pthread switch and inserting -lpthread before pkg-config --libs opencv. The solution only worked by directly linking to the lpthread library and it had to be before the opencv libraries. Have no idea why, and it also took me a good 4 hours/blood shot eyes to figure this out.

I think this was possibly a bug with my version of gcc. The only thing that worked consistently was using the flag:
-Wl,--no-as-needed
Adding -pthread didn't work at all. Adding -lpthread made some compilations work, failed for others, and just generally gave strange behavior.

Related

How to run an ARM multi-threaded program in Ruby system

I fully implemented the content of the following webpage:
http://www.gem5.org/documentation/learning_gem5/part3/running/
The program can be compiled under X86 according to webpage requirements,however I want to get an ARM binary file,so I use the following code to compile it:
aarch64-linux-gnu-g++ -o threads threads.cpp -pthread -std = c ++ 11 -static
I can compile and get the binary file, but I get the following error during running:
erminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not permitted
Since the compiled ARM binary file is not provided in gem5's bin folder, does it mean that gem5 does not support running ARM multi-threaded programs, or my compilation options are wrong?
That program fails to run with -static on both qemu-aarch64 and Ubuntu 20.04 amd64 native (always check other more stable platforms :-))
It is known that there are some nongem5-specific problems with -static and threads, see e.g.: when g++ static link pthread, cause Segmentation fault, why?
If workaround mentioned there don't work, you can now also run with dynamic linking as mentioned at: How to run a dynamically linked executable syscall emulation mode se.py in gem5? I've just tested it now and it worked with that example.
And at last note that there is a serious multithread SE Ruby problem which we are not sure how to solve: https://gem5.atlassian.net/browse/GEM5-676

G++64 compiled executables "can't run on this PC" on Windows 10

The title really says quite a bit, but let me give some context.
I am trying to work on coding without relying on an IDE like Visual Studio, so please don't suggest that I simply use an IDE to fix my problems.
Additionally, I will not accept suggestions that I use something other than G++ to compile my code with. That's not a solution to my problem, that's an alternative path completely, and not one I wish to use.
So far, I have installed MinGW-64, and am using g++64 to compile my software. For some reason, my code compiles flawlessly, but upon execution, Windows 10 tells me "This app can't run on your PC". Upon inspecting the Event Viewer, the error is that the program "cannot start or run due to incompatibility with 64-bit Windows." That doesn't make much sense to me, considering I'm compiling it with a 64-bit compiler. However, I am reasonably new to programming and to using the GNU toolchain, so perhaps I'm doing something incorrectly.
Here is my current command to compile from command line:
g++64 -c -Ic:\code\cpp\projects\git_test\include opengl_test.cpp -o opengl_test.exe
Perhaps there is something with OpenGL, FreeGLUT or GLEW that is causing the issue?
EDIT 1:
I took the suggestion to remove the -c option, and now I'm getting a lot of undefined reference errors. I tried to add the libraries, but it doesn't appear to work, even though the files are clearly in the folder I've added.
Here is my new command to compile:
g++64 -LC:\code\cpp\projects\git_test\lib -IC:\code\cpp\projects\git_test\include -lfreeglut -lglew32 -lglew32s opengl_test.cpp -o opengl_test.exe

VS2017 Linux C++ threads issue

I have been testing the VS2017 Linux C++ with remote debugger on Linux Ubuntu.
I have created a few example projects for C++ and everything has been working great until I got to threading examples.
I cannot seem to get the threads to compile as I keep getting "undefined reference to `pthread_create'" error. I know the solution to this is to add -lpthread or -pthread to the VS project properties command line but this does not seem to work in this case.
If anyone has got this working could you please point me in the right direction.
linker->input->library dependencies pthread

MinGW w64 with -municode asks for adding 'W' to the end of function name

I'm building a cross-platform application using Qt. Developed on Linux but want to build on Windows, using MinGW-w64. But this compile error happened:
For example, I have a function named func. If adopt the default compile option -municode provided by qmake, gcc says undefined reference to funcW. If manually remove this option, gcc says undefined reference to funcA.
This error only happened for one function, others are fine. That's weird to me though.
Code can be successfully built and compiled on Linux.
Any idea how it happens and how to fix it?

C++: No breakpoints work

This is probably a very basic question. However, I couldn't find any answer by searching the web.
I have a code I need to debug written in C++. For this code, I require to use GCC 4.1.2 in compatibility reasons and I am using GDB 6.6-45. I compiled the code with the -g -Wall -O0 flags to make sure the code can be debugged with GDB.
My problem is that wherever I set the breakpoint, no breakpoints get hit. Also, at the end of the run, I get this message "You can't do that without a process to debug".
By the sound of the message, I think I am missing a very trivial thing. However, I cannot figure out.
Any help would be appreciated.
EDIT:
The platform I am working on is Fedora 8 on VirtualBox. The reason why I am working on VirtualBox is because I wasn't good enough to install older version of GCC (4.1.2) properly without breaking Fedora 20, which is the latest.
As per GDB output, (it's very basic):
[localhost]$ gdb programName
GNU gdb Red Hat Linux (6.6-45.fc8rh)
... typical messages
This GDB was configured as "i386-redhat-linux-gnu"...
Using host libthread_db library "/lib/libthread_db.so.1".
(gdb) run programName (program arguments here)
...
Program outputs and messages
...
Program exited normally.
You can't do that without a process to debug.
(gdb)
What's shown above is all I have. To set my breakpoints, I did something similar to:
break main
break System::function_name
break System::line_number
and when I run info breakpoints, the breakpoints does show correct cpp file and the line number or the function name, with enabled flag to yes.
If possible try to avoid -O flag and just use -g -Wall only. I have seen some problems with -O flag in older versions. But I'm not sure whether they persist in novel gcc as well. Just give it a try.