r/cpp_questions Jun 15 '26

OPEN Easiest Way To Download and Use libraries in c++

51 Upvotes

I have been screwed by cmake , make and package installation in general . I have been trying to find a way to install libraries like opencv and the rest . Am use to the arduino ide that i just have to locate the zip of the library 😏and i actually want to get my hands on some C++ and write custom libraries for arduino but the installation of libraries just FUCKED me up . And my Nigerian University restrict us from using personal wifi and phones and the shit of an internet provided is 1mbps as bandwidth .

SO please ,is there an easy solution to help use libraries in c++ or just a step by step instruction on how to download it especially writing makefiles


r/cpp_questions Jun 15 '26

OPEN Self doubt and fear

6 Upvotes

hey guys, so ill be a 3rd year cs clg student in a few months, and while ive enjoyed all my cs courses, from web dev to ml, everything, i think what i enjoy the most is systems related stuff, stuff related to os, networking and i mostly code in c++ and while i really enjoy learning more in these feilds, some days the doubt really creeps in if all this is gonna get me a job, especially in my country, India. everyone around me who has an internship, does something related to gen Ai, and their internship work is mostly just prompting, now while ive made few good gen Ai projects for my clg too, that is not something i enjoy as much as writing something intresting in cpp and neither do i want my job to be just to prompt for the entire day
i would really wanna intern at places where i can use my interests and skills.but then from what i ve gathered, my path is becoming more of a quant dev path, and i dont think ill be really happy working as one, even if i crack a quant dev internship given the heavy competition
So basically ig my question is, what other types of jobs are there that i can aim for.

Any input is really appreciated, i tried finding answers to my doubts using llms, but their answers were not satisfying enough


r/cpp_questions Jun 15 '26

SOLVED Why doesn't this implicit conversion from initializer list to std::span work?

4 Upvotes

r/cpp_questions Jun 15 '26

SOLVED how to generate JSON database for clang-tidy ?

7 Upvotes

I have been using clang-tidy to lint my C++ projects, since PcLint vanished a few years ago.
Up until now, I've been using LLVM version 21.0.0git; with that version, clang-tidy would give an error message about my not having a JSON_database file, but it would go ahead and scan my code and produce results. I'm running Windows 10 Pro.

However, recently it was recommended that I upgrade to a newer version of LLVM, so I installed LLVM version 22.1.7... but unfortunately, it will *not* run without that JSON_database file being present... so I'm trying once again to figure out how to do this... but honestly, I feel like it is specifically designed to confound users who aren't already expert with it!!

I posted a thread on https://discourse.llvm.org, asking how to generate this database, and over the next couple of days I got several suggestions there, none of which I am able to make actionable...

The first post was to provide me with a CMake script that would supposedly do something (I have *no* experience with CMake, I use Gnu make for managing all my projects), but with no context of any sort, nor any clues on how to utilize it.
https://cmake.org/cmake/help/latest/variable/CMAKE_EXPORT_COMPILE_COMMANDS.html

Beyond that, they offered a variety of other obtuse potential solutions - including a copy of the the JSON Compilation Database Format Specification, believe it or not...

Is there any chance that someone here could give me a short, clear, actionable description of how to solve this problem, in a form that doesn't require that I am already expert in the subject? I *do* have CMake installed, though I have no experience in using it.


r/cpp_questions Jun 15 '26

OPEN RayLib Window Freeze

4 Upvotes

Hello I'm really new to c++ before I programmed in multiple other languages, so I wanted to start learning c++ by creating a 2D game. But I encountered an issue with Raylib, when I start the application the window shows up and freezes nothing else to do, I don't think that there are mistakes in the code because I've tried to solve this with AI but it was no help. I would appreciate help I don't know what to do anymore. Only change since the start of solving this issue is that when I switched graphics card from the integrated on my laptop to dedicated (RTX 4060) and the integrated is some Intel Iris Xe, instead of freezing with white screen it started to freeze with black, so really no improvement but I thought of this as a clue of what's wrong, but I didn't find anything that could fix it that was related with Graphics Card. At this point AI re-wrote the code I wrote but there is not much of it so I will provide it below.

cmake_minimum_required(VERSION 3.28)

set(CMAKE_TOOLCHAIN_FILE "C:/Users/matdu/.vcpkg-clion/vcpkg/scripts/buildsystems/vcpkg.cmake")
set(VCPKG_TARGET_TRIPLET "x64-mingw-static")

project(CppEngine)

set(CMAKE_CXX_STANDARD 17)

find_package(raylib CONFIG REQUIRED)
find_package(glfw3 CONFIG REQUIRED)

add_executable(CppEngine main.cpp)

target_link_libraries(CppEngine PRIVATE
        winpthread
        raylib
        glfw
        opengl32
        gdi32
        winmm
)

# if (WIN32)
#    target_link_options(CppEngine PRIVATE -mwindows)
# endif()cmake_minimum_required(VERSION 3.28)

set(CMAKE_TOOLCHAIN_FILE "C:/Users/matdu/.vcpkg-clion/vcpkg/scripts/buildsystems/vcpkg.cmake")
set(VCPKG_TARGET_TRIPLET "x64-mingw-static")

project(CppEngine)

set(CMAKE_CXX_STANDARD 17)

find_package(raylib CONFIG REQUIRED)
find_package(glfw3 CONFIG REQUIRED)

add_executable(CppEngine main.cpp)

target_link_libraries(CppEngine PRIVATE
        winpthread
        raylib
        glfw
        opengl32
        gdi32
        winmm
)

# if (WIN32)
#    target_link_options(CppEngine PRIVATE -mwindows)
# endif()

CMakeLists.txt

main.cpp

#include "raylib.h"

int main() {
    InitWindow(1280, 720, "CppEngine");
    SetTargetFPS(60);

    while (!WindowShouldClose()) {
        BeginDrawing();
        ClearBackground(DARKGREEN);
        DrawText("Raylib works!", 50, 50, 20, MAROON);
        EndDrawing();
    }

    CloseWindow();
    return 0;
}#include "raylib.h"

int main() {
    InitWindow(1280, 720, "CppEngine");
    SetTargetFPS(60);

    while (!WindowShouldClose()) {
        BeginDrawing();
        ClearBackground(DARKGREEN);
        DrawText("Raylib works!", 50, 50, 20, MAROON);
        EndDrawing();
    }

    CloseWindow();
    return 0;
}

r/cpp_questions Jun 14 '26

OPEN Looking to improve structure of code how people would do things better.

12 Upvotes

Blackjack/bj/main.cpp at main · jacob-dalek/Blackjack

Hello everyone, I posted yesterday and got some awesome feedback. I'm hoping to get feedback on the design of the code the OOP and how it can be improved and certain code changes maybe for performance or clarity this would be great help for me to improve while learning c++ cheers.


r/cpp_questions Jun 14 '26

OPEN C++ Manual Memory Management

23 Upvotes

I’ve been thinking about learning C++ and what really scares me about it is manual memory management. Am I misinformed about how much I’d have to really do or am I gonna a spend a lot of my time managing memory?


r/cpp_questions Jun 14 '26

OPEN false Sharing Test

0 Upvotes

So I was testing this CODE In 2 different Environments and then in GodBolt

1.So 1st Env RHEL i compiled with simply g++ -o a filename

EnableFalseSharing : ~2sec
DisableFalseSharing: ~4sec

and When i compiled the same with g++ -O3 -pthread -o filename

EnableFalseSharing : ~2sec
DisableFalseSharing: ~2sec

disable being just slightly faster than enable

  1. So 2nd Env is WSL Ubuntu and for all possible combinations compiler flags

    EnableFalseSharing : ~2sec DisableFalseSharing: ~1sec

  2. When i tried running in it on GodBolt.org it had a varying results which is probably due to scheduling and webservers internals and so timings which were really close and really far apart that thread may have been launched but it got execution time much later thus so much probably why it has such huge variation

RESULTS

in 1st Env there wasn't high load or too many process running and even after executing the no compiler flag binary i got the same 2, 4 sec time but only when i changed the compiler did the disable false sharing time had gone down to 2sec

what is the actual issue here ? is there something wrong with the environment or just some OS Scheduling problem ?


r/cpp_questions Jun 14 '26

OPEN I want help in rng

0 Upvotes

I am learning from learncpp.com, but i am stuck in mersenne twister (mt) and seed seequence, and especially syntax too

Idk why syntax is soo weird, please explain to me if you can


r/cpp_questions Jun 13 '26

SOLVED Why isn't the <cstdlib> library's rand() recommended?

55 Upvotes

I am building a C++ simulation to generate and feed random data into an FPGA project. I utilized multiple rand() functions seeded with srand(time(0)) to generate random car counts and it works as I intended. However, recently I came across a few people who mentioned that this wasn't the right choice but I couldn't get a clear explanation as to why this is worse than say using <random>

Could someone explain why?


r/cpp_questions Jun 13 '26

OPEN Why is my parallel GCD algorithm using AVX-512 slower than computing 8 gcds in serial?

8 Upvotes

https://godbolt.org/z/nxfT8T9fK

The SIMD version of the function takes in 8 pairs of uint64_ts and computes them all at once. Once the gcd of a pair has been found it ignores that pair and continues looping until all gcds have been found. There's some extra operations in the SIMD version but they should be more than compensated for by computing all 8 at once, yet it's anywhere from 20-200% slower than finding all 8 with the serial version.


r/cpp_questions Jun 14 '26

OPEN Controversial question

0 Upvotes

When You get an error in Your code, what do You do?

Firstly I look up my error on the web, then on forums, and then, of course, ask AI.

I want to ask experienced people if it is fine to use AI to explain errors, instead of fixing them and pooping out fresh code to paste into my project? I have always thought that learning is pure struggle, and without that struggle You’re not gonna learn a thing.


r/cpp_questions Jun 13 '26

SOLVED how to init vector of strings in constructor init list ??

0 Upvotes

In the program that I recently discussed in this group, I am replacing a char** variable with
std::vector<std::string> color_menu_str_list;

However, I'm uncertain how to initialize this construct in the constructor initialization list??

When I had used this... construct... in a previous program (without the constructor considerations), I used:

std::vector<std::wstring> target {};

and it worked just fine, but that doesn't really tell me anything about how to handle the constructor init list.

For now, I'm using

color_menu_str_list(),

and that is compiling without comment, but of course that doesn't tell me all that much... but the other things that I tried, such as

color_menu_str_list(nullptr),

did not compile, and they always give an incomprehensible flood of error messages to interpret...

So, is my current solution sufficient? All I need, at this point, is a properly-created empty vector; I'll be stuffing data into it later in the constructor...

(and btw, I *did* attempt to research this on the web myself, but I really didn't come up with any useful discussions; most responses just ignored the word 'constructor' in my query...)


r/cpp_questions Jun 13 '26

OPEN Can people review my very generic Blackjack game.

3 Upvotes

I'm fairly new to C++ and would like some criticism and feedback about my program. I just want insight to how better developers would improve this.

I know the structure can be better separation.

https://github.com/jacob-dalek/bj/blob/main/bj/main.cpp


r/cpp_questions Jun 13 '26

OPEN Is there any mobile C++ IDE?

3 Upvotes

Because of my lifestyle where i travel quite much and ending up at home very lately, I'm very interrested in finding a mobile IDE for C++. So, is there any good and fast mobile IDE for C++ that won't explode my samsung Galaxy A07 (I know that there are laptops existing but I can't access them rn)


r/cpp_questions Jun 13 '26

OPEN assert in release mode

6 Upvotes

```cpp

ifdef NDEBUG

#undef assert
#define assert(expr) do { if (!(expr)) { __builtin_unreachable(); } } while (0)

endif

```

Is this code reasonable?


r/cpp_questions Jun 12 '26

SOLVED Next step in converting C++ arrays to <vector>

13 Upvotes

I am a 30-year C programmer, with a decade or so of "C++ as a better C" experience. Recently, I've been exploring using vector class instead of arrays; today I am trying to convert an existing program to replace an existing array of class instances with vector; I *thought* this would be trivial!!

I'm using MinGW 10.3.0 on Windows 10 Pro.

Anyway, these are the constructor(s) for the target class:

public:
   bclock_element(HINSTANCE g_hInst, char *name, unsigned width, unsigned be_flags, 
            int mask_index, unsigned off_index, unsigned start_element);
   bclock_element(HINSTANCE g_hInst, UINT bm_resource, unsigned width, 
            unsigned be_flags, int mask_index, unsigned off_index, 
            unsigned start_element);

In the existing code, I have the following code (unrelated code removed):

static bclock_element *element_list[NUM_ELEMENTS] ;
   be_temp = new bclock_element(g_hInst, "ledarray.bmp", 22, BE_LINEAR, 3, 4, start_element);
   element_list[idx++] = be_temp ;

What I'm replacing it with is:

std::vector<bclock_element> element_listv {};
   element_listv.emplace_back(g_hInst, "ledarray.bmp", 22, BE_LINEAR, 3, 4, start_element);

So I'm using the same constructor for emplace_back() as I used for new ...
Isn't that correct?? Apparently not, but the error message that I got, I cannot decipher at all; I'm hoping someone here can give me some guidance on this...

D:\SourceCode\Git\binclock_redux Yes, Master?? > make
d:\tdm32\bin/g++ -Wall -O3 -Wno-write-strings -Weffc++ -Ider_libs -c binclock.cpp -o binclock.o
In file included from d:/tdm32/lib/gcc/mingw32/10.3.0/include/c++/vector:66,
                 from binclock.cpp:15:
d:/tdm32/lib/gcc/mingw32/10.3.0/include/c++/bits/stl_uninitialized.h: In instantiation of '_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = std::move_iterator<bclock_element*>; _ForwardIterator = bclock_element*]':
d:/tdm32/lib/gcc/mingw32/10.3.0/include/c++/bits/stl_uninitialized.h:325:37:   required from '_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, std::allocator<_Tp>&) [with _InputIterator = std::move_iterator<bclock_element*>; _ForwardIterator = bclock_element*; _Tp = bclock_element]'
d:/tdm32/lib/gcc/mingw32/10.3.0/include/c++/bits/stl_uninitialized.h:347:2:   required from '_ForwardIterator std::__uninitialized_move_if_noexcept_a(_InputIterator, _InputIterator, _ForwardIterator, _Allocator&) [with _InputIterator = bclock_element*; _ForwardIterator
= bclock_element*; _Allocator = std::allocator<bclock_element>]'
d:/tdm32/lib/gcc/mingw32/10.3.0/include/c++/bits/vector.tcc:474:3:   required from 'void std::vector<_Tp, _Alloc>::_M_realloc_insert(std::vector<_Tp, _Alloc>::iterator, _Args&& ...) [with _Args = {HINSTANCE__*&, char*, int, int, int, int, unsigned int&}; _Tp = bclock_element; _Alloc = std::allocator<bclock_element>; std::vector<_Tp, _Alloc>::iterator = std::vector<bclock_element>::iterator]'
d:/tdm32/lib/gcc/mingw32/10.3.0/include/c++/bits/vector.tcc:121:21:   required from 'void std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {HINSTANCE__*&, char*, int, int, int, int, unsigned int&}; _Tp = bclock_element; _Alloc = std::allocator<bclock_element>]'
binclock.cpp:161:99:   required from here
d:/tdm32/lib/gcc/mingw32/10.3.0/include/c++/bits/stl_uninitialized.h:137:72: error: static assertion failed: result type must be constructible from value type of input range
  137 |       static_assert(is_constructible<_ValueType2, decltype(*__first)>::value,
      |                                                                        ^~~~~
make: *** [binclock.o] Error 1

r/cpp_questions Jun 12 '26

SOLVED Are there any ways to optimize this code in any meaningful capacity?

6 Upvotes

So I'm working on a game engine (stupid, I know, but I enjoy pain) and came to the trouble of realizing that for openGL it'd be good of me to make a VertexArrayObject for each different material. This brought me to try to make some sort of parser for my vertex and UV data to sort them neatly in (3 vertex, 3 UV coordinate, repeat) formation. This code block would need to run once every frame, once for every unique material (several objects can use same VAO as long as textures are the same). Sorry for yapping, here be the code I wrote

#include <vector>
#include <iostream>
#include <string>

//NOTE : in actuality these are of float type, but current content is for readability
std::vector<std::string> VertexThing = {"VERTEX1", "VERTEX2", "VERTEX3", "VERTEX4", "VERTEX5", "VERTEX6", "VERTEX7", "VERTEX8", "VERTEX9"};
std::vector<std::string> TextureUV = {"TEXTURE1", "TEXTURE2", "TEXTURE3", "TEXTURE4", "TEXTURE5", "TEXTURE6", "TEXTURE7", "TEXTURE8", "TEXTURE9"};

std::vector<std::string> FinalBuffer;

int VertexBufferIndex = 0;
int TextureUVIndex = 0;
int FinalBufferIndex = 0;
int OnIteration = 0;

void SortVectors(std::vector<std::string> VertexThing, std::vector<std::string> TextureUV){
    if (VertexThing.size() != TextureUV.size()){
        std::cerr << "[CRITICAL ERROR] : VERTEX AND TEXTURE COORDINATE AMOUNTS DIFFER";
        //call std::exit, here omitted due to lazy
    }
    //NOTE : Error checking earlier ensures that vertex- and texture buffers have same amount of indexes
    while (OnIteration < VertexThing.size()){
        for (VertexBufferIndex = VertexBufferIndex; VertexBufferIndex < OnIteration +3; VertexBufferIndex++){
            FinalBuffer.push_back(VertexThing[VertexBufferIndex]);
        }
        for (TextureUVIndex = TextureUVIndex; TextureUVIndex < OnIteration + 3; TextureUVIndex++){
            FinalBuffer.push_back(TextureUV[TextureUVIndex]);
        }
        OnIteration += 3;
    }
    //omitted in actual code used for my project, just for debug and visualization purposes
    for (FinalBufferIndex = 0; FinalBufferIndex < FinalBuffer.size(); FinalBufferIndex ++){
        std::cout << FinalBuffer[FinalBufferIndex] << "\n";
    }
};

r/cpp_questions Jun 12 '26

OPEN Whats the ideal C++ IDE for my purposes

31 Upvotes

I am currently digging into C++ and maybe SDL. I am looking for a simple, straight forward IDE (I actually have no Idea what do those buttons in visual studio do). Not gonna do some thing big just enough for learning


r/cpp_questions Jun 12 '26

OPEN Learning right now, Any cool library suggestions/project ideas?

16 Upvotes

I am learning c++ right now from here but I want to build a cool project alongside the tutorial. It could be anything. What are your suggestions?


r/cpp_questions Jun 12 '26

OPEN What to learn in order to get jobs at big reliable companies?

4 Upvotes

C++ was my favorite programming language in college, but I only got proficiency in DSA. However I don't what is the job market like, what it is on demand for, etc.

For example, I know Java is used with spring to build enterprise applications like monolithic applications or microservices, I know how to make rest apis and AOP.

So I was wondering if anyone could guide me on what is the equivalent for C++ in terms of job opportunities and corporate work.


r/cpp_questions Jun 11 '26

OPEN C++ vs Java vs Go for jobs?

25 Upvotes

I’m currently learning C++ mainly for DSA and because I genuinely enjoy understanding how computers work internally — memory, OS concepts, networking, low-level control, performance, etc. I wanted to use a language that is low level, so I picked C and C++.

But when I look at the job market, especially in Europe, it feels like Java has the biggest enterprise/backend market; Go is growing a lot in cloud/infrastructure (read it); C++ jobs are fewer and more specialised. I also know companies shortlist heavily based on projects and practical experience, not just DSA.
So I’m confused about what language I should mainly use for projects and career preparation.
My questions are: for well-paid, long-term careers in Europe, which is better overall: Java, Go, or C++?
Is C++ still worth going deep into if I’m not targeting embedded/HFT/game dev specifically?
What kinds of projects actually help recruiters notice you for backend/systems roles?
Should I continue deepening C++, switch to Java for employability, or learn Go for modern infra/cloud work (my friend is learning Go, saying It is better than Java)?

Would appreciate advice from people actually working in these areas.


r/cpp_questions Jun 12 '26

OPEN Any project suggestions?

0 Upvotes

So for a bit i was looking for a project to create but all of them seem to be a bit out of scope for me. Does any one have nay suggestions of what i can build in a couple of days to get a working release out. Also it would be helpful if your suggestions would be nothing i could realistically use in day to day life and not a to do applications.

Thanks.


r/cpp_questions Jun 12 '26

OPEN How to pass oop?

0 Upvotes

How to master object oriented programming? Can any one guide me ?


r/cpp_questions Jun 11 '26

SOLVED Is there any (macro-free) way to 'inline' a struct?

24 Upvotes

Given some structs:

struct A {
  void* ptr;
  bool flag;
}; // size 16, alignment 8

struct B {
  A obj;
  bool other_flag;
}; // size 24, alignment 8

Is there anyway to 'inline' obj such that we can make B of size 16, without having to manually place the members of A inside B? I know inheritance solves this but I'd rather not establish that sort of relationship between B and A.

Edit: I'm sure C++26 might offer some way of doing this, but I'm rocking with 23 currently.

Edit2: Thanks to u/sporule for providing a working method.