code::blocks new thread mingw

Hi,
im new in this and need some help.
i already read other threads in searched in google, but i cant fixed the issues.

i want to creat a new thread in c::b. Im on Ubuntu.

Ive installed the latest mingw with $ sudo apt-get install gcc-mingw-w64
but it dosnt fixed the problem.

so what i have to do?
i would be very pleased to get a step by step instruction.

thanks so much

sam
...but it dosnt fixed the problem.

What problem ?
oh sorry ive forgott

#error This file requires compiler and library support for the \
ISO C++ 2011 standard. This support is currently experimental, and must be \
enabled with the -std=c++11 or -std=gnu++11 compiler options.
Ive installed the latest mingw with $ sudo apt-get install gcc-mingw-w64


mingw is for Windows, on Linux one can use g++ directly. See if it is already installed (it probably will be)- in a terminal type g++ -v , tell us what the output is.

But really Google is a big help, searching for "c++ development on ubuntu" yields this:

https://itsfoss.com/c-plus-plus-ubuntu/

As the page says Eclipse is a much better IDE than CodeBlocks.


gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
maybe i use <pthread.h> instead of <thread>.

is it the same?
It is not the same.

Create this file, named main.cpp:

1
2
3
4
5
#include <iostream>
int main()
{
  std::cout << "Running";
}


Do not create it with an IDE. Create it with a text editor.

Do NOT use minGW. MinGW is Minimal GNU FOR WINDOWS. You're not using Windows.

When you have created that file, compile it at the command line (in the directory containing that file) with the command:

g++ ./main.cpp

It should produce an executable file, named a.exe

Then, run a.exe at the command line:
./a.exe

It should output "Running".

If that all works, we know that you have the compiler installed properly and it works.

http://www.cplusplus.com/forum/beginner/1/

compile with

g++ -std=c++11 -Wall -Wextra -pedantic-errors -pthread
You can update to a later compiler version

http://www.cplusplus.com/forum/unices/227621/#msg1036115

It might be a good idea to update to a later version of Ubuntu

Google and wiki are your friends :+)
g++ ./main.cpp
It should produce an executable file, named a.exe


this created a.out file

Then, run a.exe at the command line:
./a.exe


thats not working also i type ./a.out


g++ -std=c++11 -Wall -Wextra -pedantic-errors -pthread main.cpp -o myprog

./myprog


g++ -std=c++11 -Wall -Wextra -pedantic-errors -pthread main.cpp -o myprog

./myprog


that works. thanks.

But my Problem is to create new Threads in Code::Blocks

OK my whole Project is to build a GUI with Code::Blocks and a TcpIP Socket that runs in a seperated Thread.

Or where else can i write my TcpIP Socket code. because i have no int main() {}...


Last edited on
Now get that code building and running in Code::Blocks

At that point, you know it works.

Then you add

#include <thread>

and you can start using threads.

Remember to tell Code::Blocks that you're not using the MinGW compiler. You're using straight g++
Last edited on
if i add

#include <thread>

i get this #error above...

#error This file requires compiler and library support for the \
ISO C++ 2011 standard. This support is currently experimental, and must be \
enabled with the -std=c++11 or -std=gnu++11 compiler options. 
Last edited on
g++ doesn't use C++11 by default until GCC 5.x. https://gcc.gnu.org/gcc-5/changes.html
Add the commmand-line argument -std=c++11
...or, update your compiler. That's probably the better option here.
Last edited on
thanks,

ive updated the GCC to gcc-7 on this way

https://www.youtube.com/watch?v=fIZVuPJDDic
hmm. but it seems that it doesnt compile anymore...

Now i get "Process terminated with status 127" in Build-log

why is it so difficult...

i type in terminal gcc -v and i get
gcc version 7.2.0 (Ubuntu 7.2.0-1ubuntu1~14.04) 


if i type g++ -v
...is not installed....


but if i type sudo apt-get install g++
g++ is already the latest version

Last edited on
TheIdeasMan wrote:
You can update to a later compiler version

http://www.cplusplus.com/forum/unices/227621/#msg1036115


I gather you didn't read that message well enough. Maybe your g++ is now g++-7 though.

Ubuntu has this concept of a stable version of things being installed, and they stay that way until one updates them via a ppa repository.
Topic archived. No new replies allowed.