Code Monkey home page Code Monkey logo

cpp's Introduction

G++

Programowanie w C++ (g++ linux curl, opengl, sfml, thread).

Instalacja

https://github.com/atomjoy/cpp/blob/master/cpp-wiki/0-install.md

Kompilacja

https://github.com/atomjoy/cpp/blob/master/cpp-wiki/1-compile.md

# Kompiluj
sudo g++ -c main.cpp
# Lub
sudo g++ -c main.cpp -o main.o

# Plik wykonywalny
g++ -o main-app main.o

# Uruchom
./main-app

Kompilacja parametry

# Błędy, debugowanie
-g -Wall -pedantic 

# Import bibliotek
-std=c++11 -lpthread -lcurl -I. -L.

# Import gtk
`pkg-config --cflags --libs gtk+-3.0 gtkmm-3.0 giomm-2.4 gl`

# Import SFML
-lsfml-graphics -lsfml-window -lsfml-system

Przykład kodu

/*
Kompilacja
sudo g++ -c main.cpp -std=c++11 -lpthread
sudo g++ -o main-app main.o -std=c++11 -lpthread
./main-app

Lub
sudo g++ main.cpp -std=c++11 -pthread -o main-app
*/
#include <iostream>
#include <thread>
#include <chrono>

//This function will be called from a thread
void call_from_thread(int n) {  
  // std::this_thread::sleep_for(std::chrono::milliseconds(200));
  std::this_thread::sleep_for(std::chrono::seconds(n));
  std::cout << "Hello, World from thread " << n << std::endl;
}
 
int main() {
  
  std::cout << "Hello, World from main thread " << std::endl;
  
  //Launch a thread
  std::thread t1(call_from_thread, 1);
  std::thread t2(call_from_thread, 2);
 
  //Join the thread with the main thread
  t1.join();
  t2.join();
  
  std::cout << "Bye, from main thread " << std::endl;
  
  return 0;
}

Przykład pliku Makefile

nano Makefile

CXX = g++
CXXFLAGS = -Wall -g -pedantic
CXXCMD = -std=c++11 -lpthread -lcurl
CXXSFML = -lsfml-graphics -lsfml-window -lsfml-system
CXXGTK = `pkg-config --cflags --libs gtk+-3.0 gtkmm-3.0 giomm-2.4 gl`

all: main-app

main-app: main.o Date.o Num.o
	$(CXX) $(CXXFLAGS) $(CXXGTK) $(CXXSFML) $(CXXCMD) -o main-app main.o Date.o Num.o

main.o: main.cpp Date.h Num.h
	$(CXX) $(CXXFLAGS) $(CXXGTK) $(CXXCMD) -c main.cpp

Date.o: Date.h
Num.o: Num.h

clean:
	rm -rf main-app *.o

Uruchom Makefile

# Uruchom kompilację
sudo make

# Wyczyść
sudo make clean

Visual Code C++ Run Task konfig

https://github.com/moovspace/cpp/blob/master/.vscode/tasks.json

// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
// ${fileDirname}
// ${fileBasenameNoExtension}
// ${workspaceFolderBasename}
    
{    
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "BUILD NOW",
            "command": "g++",
            "args": [
                "-g",
                "-Wall",
                "-pedantic",
                "${file}",
                "-o",
                "${fileBasenameNoExtension}"
            ],
            "problemMatcher": [],
            "group": "build"
        },
        {
            "type": "shell",
            "label": "RUN NOW",
            "command": "./${fileBasenameNoExtension}",
            "dependsOn": [
                "BUILD NOW"
            ],
            "problemMatcher": []
        }
    ]
}

cpp's People

Contributors

atomjoy avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.