Questions tagged [g++]

g++ is the C++ frontend to the GNU Compiler Collection (GCC). It's the de facto standard compiler for C, C++, Go, Fortran, and Ada on Linux and supports many other languages and platforms as well. Apart from the compiler, GCC has a toolchain (libc, libstdc++, objdump, nm etc.) that is widely used on several platforms and systems.

Filter by
Sorted by
Tagged with
0 votes
0 answers
29 views

How to get the iterator of a list of type <T> in C++? [duplicate]

I'm beginning with C++ and I'm struggling with templates. Basically, I have this code: #include <iostream> #include <list> using namespace std; // ... template <typename T> void ...
ThomasG2201's user avatar
0 votes
0 answers
14 views

C++ type conversion do rounding automatically

Environment: g++ (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0 codes: #include <string> #include <cstdio> #include <iostream> #include <vector> using namespace std; int main(){ ...
LiYanjie's user avatar
1 vote
1 answer
34 views

Is there sth. similar to _udiv128 for gcc?

Is there sth. similar to MSVC's _udiv128() for gcc ? If I use __int128 variable as the dividend and have an normal "/"-divide the compiler doesn't know that the result fits in an unsigned ...
Edison von Myosotis's user avatar
-1 votes
0 answers
90 views

G++ failing to resolve [] operator overloading

Summary G++ fails to compile and gives error when accessing an instance of my class via the [] subscript operator, although it compiles and runs when calling ->operator[](), as it should be ...
HernanATN's user avatar
  • 141
-1 votes
1 answer
88 views

gcc / g++ command does nothing and exits with code 1

gcc / g++ throws exit code 1 and does nothing I tried to compile my c++ / c files using gcc / g++ ! It did nothing the command neither produced a.exe file it didn't throw any error ,(print anything ...
infinull's user avatar
1 vote
2 answers
46 views

How can I replace gcc with g++-11 for C++20 when running cmake

Specs: WSL, ubuntu 22.04 cmake version 3.25.2 g++ version: 11.4.0 gcc version: 11.4.0 I was doing lab0 of CS144, Spring 2023 of Stanford when I got stuck at the very beginning. When I ran cmake --...
Overstacked's user avatar
-2 votes
0 answers
67 views

Order of evalutation in c++ [duplicate]

I am a beginner to c++ programming,i came across this question in my assignment, the question asks to determine the output of the following code #include<iostream> #include <cmath> int ...
Entoninus's user avatar
-2 votes
0 answers
49 views

ask about code run in C++, visual studio code

Although i have already install an environment to code C++, i cant run code in visual studio code by press ctrl f5 and use g++.When i run code by ctrl + f5 i will have a problem in picture 1 .i can ...
1Huy's user avatar
  • 1
-1 votes
0 answers
17 views

cc1 error when compiling tensorflow from source (linux)

When I compile tensorflow from source, I get this error: ERROR: /root/.cache/bazel/_bazel_root/6dca306fa8d519b766333998e9fd499a/external/XNNPACK/BUILD.bazel:2884:19: Compiling src/operators/prelu-nc....
izash's user avatar
  • 49
0 votes
0 answers
30 views

how to solve the redefinition error in c++ [duplicate]

For some reason when i run a c++ program with special characters they are not displayed as they should, so i made this header file: #ifndef Tildes_h #define Tildes_h unsigned char a_con_tilde = 160; ...
user avatar
2 votes
2 answers
1k views

ld: warning: ignoring duplicate libraries: '-lgcc' after the recent update of Xcodebuild tools

Recently, I upgraded to Xcode 15, and with that the update of the xcodebuild tools. However, suddenly, my standalone C++ applications are not able to use the g++-13 compiler for some reason? Anyone ...
Devansh Nigam's user avatar
1 vote
0 answers
51 views

Question with 'rbreak' command in gdb, template function not defined in source file

I want to set breakpoints for all type of the template function foo. Here is my code. #include <iostream> template <typename T> void foo(T t) { std::cout << t << std::endl; }...
RK Z's user avatar
  • 11
0 votes
1 answer
12 views

g++ not able to create object file, .o no such file or directory

Trying to learn makefiles on my own, I'm getting this strange behavior (but maybe not so strange for you :-) ) I have a simple helloworld project with only 1 source file. g++ is able to create the exe ...
Sébastien DA SILVA's user avatar
0 votes
0 answers
41 views

Compiling assembly (.s file) using gcc error c++ standard library

I am trying to compile an .s file I produced using llvm (llc) back to an .exe file. When trying to compile the .s file using g++ with g++ output.s -o test.exe, I get multiple errors of output.s:344: ...
kevl's user avatar
  • 9
0 votes
0 answers
14 views

How do I properly add files to a Code::Blocks project?

I made a code blocks(ninja) GLFW project through cmake and it didn't auto generate any main.cpp file for me to start writing the actual program so I had to create it manually. When I added it to the ...
DogWrangler23's user avatar
1 vote
0 answers
54 views

C++ ansi Escape Code Doesn't Color The Text [duplicate]

I'm trying to use ANSI escape codes to color a text, my code looks like this: #include <iostream> int main() { std::cout << "\033[31m" << "\n"; std::...
SimpfeyIsDumb's user avatar
-1 votes
1 answer
45 views

How to get the factorial of a number using std :: accumulate()? [closed]

Hello! I was using the function std::accumulate() to see whether it would return the factorial of 10 on applying a multiplication operation on a sequence of the natural numbers from 1 to 10, as ...
Ali Kamel Ali's user avatar
-2 votes
0 answers
25 views

Issues with C++ Templates [duplicate]

I am trying to create an abstract interface for Trees using c++ templates. I am facing some issues with it. Here is the code I have written: tree.h #ifndef __TREE_H_ #define __TREE_H_ template <...
Ricky's user avatar
  • 631
0 votes
1 answer
46 views

GCC interrupts compiling with this message "internal compiler error: in instantiate_type" on simple coroutine

I get GCC compiler internal error message when compile my code. But MSVC and Clang compile it fine. This is reduced to example one simple "yield coroutine". I use x86-64 gcc 13.2 compiler ...
Алексей Фет's user avatar
0 votes
1 answer
10 views

Why sizeof of char* allocated with malloc return 8?

I'm compiling with g++. I have this code: char* charP = (char*) malloc(1); I understood it as allocate 1 byte. When I do a printf for the size of charP it shows 8. printf("size of charP is %lu \n&...
binary_assemble's user avatar
1 vote
2 answers
86 views

Possible false positive from [-Wdangling-reference] using g++

Consider the following code: #include <iostream> #include <vector> #include <ranges> int main() { std::vector<int> a{ 1, 2, 3, 4, 5 }; std::span<const int> b{ a };...
Bob__'s user avatar
  • 12.4k
-2 votes
0 answers
51 views

Linker can't find __throw_bad_array_new_length?

I tried to run simple program in c++ which includes SFML/Graphics.hpp I try: g++ sfml.cpp -o mySFMLApp -lsfml-graphics -lsfml-window -lsfml-system using g++ (GCC) 10.3.1 on Ubuntu 22.04.3 LTS and ...
Jakub's user avatar
  • 1
0 votes
0 answers
26 views

C++ code running using WSL Ubuntu, but not able to debug code in VS Code

I am trying to set up my VS code with WSL Ubuntu to run C++ code. I have installed gdb and g++ and able to run code using Ubuntu and VS code terminal. However, when I am trying to debug the code in VS ...
Sachin's user avatar
  • 1
-1 votes
0 answers
32 views

c++: Can linkage be proponed into compile time of object?

I am unable to find the correct cmd command for g++ such that I can compile a source file into an object file with all its necessary linkage preemtively. Example I have three files: foo.hpp declares ...
Darika Ranganathan's user avatar
-1 votes
0 answers
13 views

Undefined Refrence whiel cross compiling > GLIBCXX_3.4.9'

Hello everybody i am currently trying to cross compile an OpenCV applciation for a ARMs target running Linux. My host machine is running linux 20. I cross compiled all the libraries and linked them in ...
APC1Wi's user avatar
  • 1
-1 votes
0 answers
16 views

g++ doesn't show up in build task options (VS Code)

I have installed MinGW-64 and added the bin folder to the Environment Variables. I was able to successfully compile my C++ program from cmd, PowerShell, and CodeBlocks. However, I couldn't seem to do ...
ideals_go's user avatar
0 votes
0 answers
26 views

Recognizing gcc 4.8.5 instead of 4.9.2 (CentOS 7/RHEL 7)

Good day to any kind soul and thank you in advance. I'm having some troubles running a node application on a CentOS 7 distro, previously I had tried to run the application on a CentOS 6 instance to no ...
Arturo Obregon's user avatar
0 votes
0 answers
91 views

How to indicate the array length to the c++ compiler

A common reason why code involving character sequences aren't vectorized is demonstrated by the following example. find_a() is a toy function that sets the current_index pointer to the next occurring '...
NoNae's user avatar
  • 331
-1 votes
0 answers
56 views

Why do you have to specify -lpthread for <thread> library and compiling with g++ in linux but not for g++ in macOS?

So when I compile a C++ program using the Standard Library <thread> header, I have to pass -lpthread to g++ when in Linux. If I don't it does not compile. However I leave it off in macOS and the ...
Carlo Tambuatco's user avatar
1 vote
0 answers
37 views

g++ can't find include files even with -I

I'm trying to compile an example from a C++ library on Github. Here is the command I used to compile the code: $ g++ -g main.cpp -o main -I~/NMEA2000_socketCAN -I~/NMEA0183 -I~/NMEA2000/src -lnmea2000 ...
William Q's user avatar
0 votes
0 answers
29 views

How to make a program link to a library at runing time instead of compile time?

How can I compile my program with this declaration files( .h files) without definitions files( .so files)? How to make a program link to a library at runing time instead of compile time? I try to ...
Gaomozi's user avatar
-2 votes
0 answers
37 views

Install gcc=9.3 on MacOS

I need to compile c++ with gcc9.3, but I found no way to install gcc9.3 with brew, so I tried to compile it from source file. But I always got this error: ld: symbol(s) not found for architecture ...
Ibroad's user avatar
  • 25
0 votes
0 answers
68 views

C++ core dump caused by "Hello world"

I was testing Vim to write code and wrote a simple "Hello world" program to test it. Using g++, the program seemingly compiled fine with the command g++ helloworld.cpp -o helloworld (no ...
user avatar
1 vote
0 answers
43 views

New array-bounds and stringop-overflow GCC 13 warnings in spdlog+gtest program

I updated the operating system from Fedora 37 to Fedora 38, and my program started to produce new compilation warnings: array-bounds and stringop-overflow. The program depends on the libraries from ...
Fedor's user avatar
  • 17.3k
-2 votes
1 answer
62 views

static member of dynamic library can not be initialized on Linux(GNU GCC) but can initialized on macOS (Clang)

It seems that the linker of gnu drop test.cpp since that there is no reference in main.cpp. But I really need to initialize some static variable like this in my project. // main.cpp #include "...
XY_cpp's user avatar
  • 13
0 votes
0 answers
49 views

When I compile a c++ project, I have no problem on my own computer. Now, I switch to the cloud server and an error occurs

This is part of the error message, mainly about stl, and the part that is not shown is similar. g++ -std=c++11 -o server main.c ./threadpool/threadpool.h ./http/http_conn.cpp ./http/http_conn.h ./lock/...
大鸡啄米mm's user avatar
0 votes
0 answers
23 views

Overwrite default system include directories using sysroot

I'm trying to cross compile for AArch64 aarch64-linux-gnu-g++. I specified sysroot using --sysroot=/home/aaron/Sysroot_Debian-Buster. However, when trying to #include <signal.h>, gcc is still ...
Aaron Liu's user avatar
1 vote
0 answers
48 views

Cannot compile a C++ Program due to Undefined Reference errors with Mapnik

I installed mapnik 4.0.0 from source using cmake. Now Im trying to run C++ default example: #define _GLIBCXX_USE_CXX11_ABI 0 #include <mapnik/map.hpp> #include <mapnik/load_map.hpp> #...
syat-cd's user avatar
0 votes
1 answer
60 views

Building with libc++ and gcc: -Wmaybe-uninitalized

I am running a build with gcc and libc++ (llvm). Since update to debian bookworm I get: /usr/lib/llvm-14/include/c++/v1/regex:1384:8: warning: ‘<unnamed>.std::__1::__state<char>::...
kuga's user avatar
  • 1,499
2 votes
0 answers
15 views

CMake goes into an infinite loop when there are two stand-alone subprojects with two different compilers within the same build [duplicate]

I am new to CMake. What I want to have is two different stand-alone subprojects within one "root" project such that those two subprojects could be built independently. Given that those two ...
ramgorur's user avatar
  • 2,104
0 votes
0 answers
59 views

OpenMP using a large amount of CPU even for "do nothing" operations

I've inherited a project that uses OpenMP and I've found that the application inexplicably uses a lot of CPU even when doing nothing. Eventually I narrowed this down to the OpenMP usage (removing it ...
user2445507's user avatar
1 vote
1 answer
76 views

Why doesn't -fsanitize=undefined pick up on (what I think is) UB?

auto vec = std::vector<int>({1, 2, 3}); std::cout << *vec.end() << std::endl; Here is some simple code that I believe to be UB. However, compiling this with the following steps: g++ ...
doliphin's user avatar
  • 762
12 votes
2 answers
1k views

C++20's std::views::filter not filtering the view correctly

I was writing a simple C++ program that generates a list of random integer values from a normal distribution, then takes first N generated items and filters them so that their absolute value is ...
God I Hate Python's user avatar
0 votes
0 answers
5 views

Why subclass may refer to anchestor fields while template subclass may not?

I see it is very uncomfortable to be obliged to use anchestor class fields by prefixing them with the anchestor class while this is not required normally, "WHY IS THAT?" and there is any ...
George Kourtis's user avatar
1 vote
0 answers
73 views

How to determine when the compilation of a cpp file is too slow? [closed]

It takes me 14s to compile a file which has 42000 lines of code in C++ with g++ 9.3.0 How to know if this compilation time is excessive or not ? EDIT : This compile time doesn't satisfy me because I ...
Tesla123's user avatar
  • 319
0 votes
0 answers
57 views

g++ complains that ISO C++ 2011 standard is not enabled whereas I use -std=c++17

I have an issue with CMake and g++ in my Travis-Ci Ubuntu environment. Compilation failed with the following error message: In file included from /usr/include/c++/10/cinttypes:35, ...
Quicky's user avatar
  • 403
0 votes
2 answers
164 views

clang++ compiles unreachable function, g++ doesn't

I saw this meme on Instagram about some C++ code that should not output anything but does. The code is: #include <iostream> int main() { while (1) ; } void unreachable() { std::...
MrKleeblatt's user avatar
1 vote
0 answers
35 views

How do I safely distribute a ninja component build?

Context I am compiling Chromium using autoninja and the is_component_build build flag which quote "links many parts of the build into separate shared libraries to avoid the long link step at the ...
Constantin's user avatar
0 votes
0 answers
24 views

fatal error: cannot execute cc1 execvp" when using x86_64-w64-mingw32-gcc

I'm trying to compile a file using the following command: x86_64-w64-mingw32-gcc reverse.cpp -o reverse.exe -s -ffunction-sections -fdata-sections -Wno-write-strings -fno-exceptions -fmerge-all-...
Shinomoto Asakura's user avatar
0 votes
3 answers
69 views

Why the Class definition does compile one way and not the other?

I simplified the code to 2 files compiled independently and linked together. file: main.cpp class A{ public: int value; A(int); }; #include <iostream> using namespace std; ...
George Kourtis's user avatar

1
2 3 4 5
210