I am trying to add -std=c++0x into the eclipse Ubuntu but I do not know how to add it.
My original set up:
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/copy2.d" -MT"src/copy2.d" -o "src/copy2.o" "../src/copy2.cpp"
Does not include -std=c++0x that's why giving me the error when I run std::stoi:
error: stoi is not a member of std
My expectation:
g++ -std=c++0x -O0 -g3 -Wall -c -fmessage-length=0 MMD -MP -MF"src/copy2.d" -MT"src/copy2.d" -o "src/copy2.o" "../src/copy2.cpp"
Related
I have a compilation line the I'm trying to parse, all I'm trying to get is the full file name with the extension from the compilation line, but the compilation line can contain different file extension like '.c' or '.asm' or '.cpp' and of course the order of parameters can be different.
For example :
gcc -DDEF_SOMETHING -g3 -Iinclude -Wall -c file1.c -o file1.o
or
gcc -DDEF_SOMETHING -g3 -Iinclude -Wall -c file1.asm -o file1.o
or
gcc -DDEF_SOMETHING -g3 -Iinclude -Wall -c file1.asm.c -o file1.asm.o
or
gcc -DDEF_SOMETHING -g3 -Iinclude -Wall -o file1.o -c file1.c
or
gcc -DDEF_SOMETHING -g3 -Iinclude -Wall -o file1.asm.o -c file1.asm.c
or
gcc -DDEF_SOMETHING -g3 -Iinclude -Wall -c -o file1.asm.o file1.asm.c
The file names are sometimes enclosed with " for example :
gcc -DDEF_SOMETHING -g3 -Iinclude -Wall -c "file1.c" -o "file1.o"
gcc -DDEF_SOMETHING -g3 -Iinclude -Wall -c "file1.asm" -o file1.o"
gcc -DDEF_SOMETHING -g3 -Iinclude -Wall -c "file1.asm.c" -o "file1.asm.o"
gcc -DDEF_SOMETHING -g3 -Iinclude -Wall -o "file1.o" -c "file1.c"
gcc -DDEF_SOMETHING -g3 -Iinclude -Wall -o "file1.asm.o" -c "file1.asm.c"
I tried the following regular expression in python3 :
r'(?:\")?(\S+(?:\.cpp|\.cxx|\.cc|\.c|\.asm|\.s))(?:\")?'
and
r'(?:\")?(\S+(?:\.cpp|\.cxx|\.cc|\.c|\.asm|\.s)+)(?:\")?'
but I'm getting wrong results
for example for the last case I get :
file1.asm
You can use capture groups to get the file name, and since you always know which flag precedes a file name (-c or -o), you can just get the whole word after it.
The regex is this one:
(?<!-o)\s"?([^-]+?\.[^\s"]+)
And you can use it in a script like so:
import re
pattern = r'(?<!-o)\s"?([^-]+?\.[^\s"]+)'
matcher = re.compile(pattern)
matcher.findall("gcc -DDEF_SOMETHING -g3 -Iinclude -Wall -c file1.c -o file1.o")
# ['file1.c']
matcher.findall("gcc -DDEF_SOMETHING -g3 -Iinclude -Wall -c file1.asm -o file1.o")
# ['file1.asm']
matcher.findall("gcc -DDEF_SOMETHING -g3 -Iinclude -Wall -c file1.asm.c -o file1.asm.o")
# ['file1.asm.c']
matcher.findall("gcc -DDEF_SOMETHING -g3 -Iinclude -Wall -o file1.o -c file1.c")
# ['file1.c']
matcher.findall("gcc -DDEF_SOMETHING -g3 -Iinclude -Wall -o file1.asm.o -c file1.asm.c")
# ['file1.asm.c']
matcher.findall('gcc -DDEF_SOMETHING -g3 -Iinclude -Wall -o "file1.asm.o" -c "file1.asm.c"')
# ['file1.asm.c']
matcher.findall('gcc -DDEF_SOMETHING -g3 -Iinclude -Wall -c -o file1.asm.o file1.asm.c')
# ['file1.asm.c']
I am attempting to compile a program that uses ranged based for loops, and a couple other features available only in c++11 and above. When I attempt to compile the program using a makefile in the terminal, I get this error:
error: range-based ‘for’ loops are not allowed in C++98 mode
and some warnings:
warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
What's annoying is that this has happened before, but it just resolved itself. However, this time it has not resolved itself.
Here's my makefile:
main: main.o
g++5 -std=c++11 -Wall -Werror -g *.cpp -o lab4
Here are some examples of things I have tried to change in the makefile, but did not work.
g++-5 -std=c++11 -Wall -Werror -g *.cpp -o lab4
g++5 -std=gnu++11 -Wall -Werror -g *.cpp -o lab4
g++5 -std=c++0x -Wall -Werror -g *.cpp -o lab4
g++ -std=c++11 -Wall -Werror -g *.cpp -o lab4
g++ -std=gnu++11 -Wall -Werror -g *.cpp -o lab4
All of the previous examples result in similar warnings and errors. What can I do to fix the problem?
I'm getting errors when trying to run the HTTP server example that comes with the source of the boost library, under the path: boost_1_59_0/libs/asio/example/cpp11/http/server/.
I already ran this following commands in the boost_1_59_0 directory:
$ ./bootstrap.sh
$ sudo ./bjam install
$ sudo ./b2 install
After installing all targets, i tried to compile the main.cpp and the server.cpp with this command: g++ -std=c++0x -o main main.cpp -I "/home/user/Desktop/boost_1_59_0" -L "/home/user/Desktop/boost_1_59_0/libs/" -lboost_system.
Any suggestion on how to compile this server example?
I linked all files from the boost_1_59_0/libs/asio/example/cpp11/http/server/ folder after the main.cpp, as #Richard Hodges suggested. It still didn't work, i got errors concerning lpthread, so i added it to the compiling options. The program compiled but it failed the execution, returning an error saying that it didn't find the library libboost_system.so.1.59.0. I tried linking the folders with -L /path/to/library but it didn't work.
Solution:
My compilation command:
g++ -std=gnu++0x -o main main.cpp server.cpp connection.cpp connection_manager.cpp reply.cpp mime_types.cpp request_handler.cpp request_parser.cpp -I "/home/user/Desktop/boost_1_59_0" -lboost_system -lpthread
I solved it with this commands:
$ LD_LIBRARY_PATH="/usr/local/lib/"
$ sudo ldconfig
And then I just ran the executable and it worked!
Here's a simple makefile I just concocted that works:
all:server
CPPFLAGS+=-std=c++11 -Wall -pedantic
CPPFLAGS+=-g -O2
CPPFLAGS+=-pthread
LDFLAGS+=-lboost_system
%.o:%.cpp
$(CXX) $(CPPFLAGS) $^ -c -o $#
server:$(patsubst %.cpp,%.o,$(wildcard *.cpp))
$(CXX) $(CPPFLAGS) $^ -o $# $(LDFLAGS)
It runs make:
g++ -std=c++11 -Wall -pedantic -g -O2 -pthread connection.cpp -c -o connection.o
g++ -std=c++11 -Wall -pedantic -g -O2 -pthread connection_manager.cpp -c -o connection_manager.o
g++ -std=c++11 -Wall -pedantic -g -O2 -pthread main.cpp -c -o main.o
g++ -std=c++11 -Wall -pedantic -g -O2 -pthread mime_types.cpp -c -o mime_types.o
g++ -std=c++11 -Wall -pedantic -g -O2 -pthread reply.cpp -c -o reply.o
g++ -std=c++11 -Wall -pedantic -g -O2 -pthread request_handler.cpp -c -o request_handler.o
g++ -std=c++11 -Wall -pedantic -g -O2 -pthread request_parser.cpp -c -o request_parser.o
g++ -std=c++11 -Wall -pedantic -g -O2 -pthread server.cpp -c -o server.o
g++ -std=c++11 -Wall -pedantic -g -O2 -pthread connection.o connection_manager.o main.o mime_types.o reply.o request_handler.o request_parser.o server.o -o server -lboost_system
And the test program runs:
$ ./server 0.0.0.0 9889 . &
$ GET http://localhost:9889/main.cpp > main.cpp.0
Check the files
$ md5sum main.cpp*
be5dc1c26b5942101a7895de6baedcee main.cpp
be5dc1c26b5942101a7895de6baedcee main.cpp.0
Don't forget to kill the server when you're done
When compiling my code I run into an issue as follows:
io.cpp:21: undefined reference to `PQconnectdb'
as well as all other instances of missing postgres function calls occurring in my code. Obviously this is a linking problem, I'm just not sure what the link issue is.
I'm compiling with the following:
mpiCC -c -O2 -g -Wall -Werror -I /usr/include/postgresql/ decisioning_mpi.cpp
g++ -c -O2 -g -Wall -Werror -I /usr/include/postgresql/ io.cpp
g++ -c -O2 -g -Wall -Werror -I /usr/include/postgresql/ calculations.cpp
g++ -c -O2 -g -Wall -Werror -I /usr/include/postgresql/ rules.cpp
g++ -c -O2 -g -Wall -Werror -I /usr/include/postgresql/ Instrument.cpp
g++ -c -O2 -g -Wall -Werror -I /usr/include/postgresql/ Backtest_Parameter_CPO.cpp
g++ -c -O2 -g -Wall -Werror -I /usr/include/postgresql/ Backtest_Trade_CPO.cpp
g++ -c -O2 -g -Wall -Werror -I /usr/include/postgresql/ Data_Bar.cpp
mpiCC -o decisioning_mpi -O2 -g -Wall -Werror -L/usr/lib -lm -lpq decisioning_mpi.o
io.o calculations.o rules.o Instrument.o Backtest_Parameter_CPO.o Backtest_Trade_CPO.o Data_Bar.o
It should be noted that this is the correct directory for libpq-fe.h and that I'm linking pq, so I'm not exactly sure why the postgres functions aren't linking correctly. I'm running Ubuntu 12.04 and installed psql (PostgreSQL) 9.1.6 from synaptic. As well I'll short circuit this, I am using #include "libpq-fe.h".
Any ideas on how I can get this linking issue resolved?
put -L/usr/lib/ -lm -lpq in the end of link command, the linker can then find the symbols
mpiCC -o decisioning_mpi -O2 -g -Wall -Werror decisioning_mpi.o io.o \
calculations.o rules.o Instrument.o Backtest_Parameter_CPO.o \
Backtest_Trade_CPO.o Data_Bar.o -L/usr/lib -lm -lpq
GCC Link Reference:
http://www.network-theory.co.uk/docs/gccintro/gccintro_18.html
I've just tried to debug my C++ program after upgrading to Ubuntu 11.10 and it appears the gdb version I'm running (7.3) is broken for debug output.
What happens:
I hit debug, Console window pops up, Message appears at the top:
warning: GDB: failed to set controlling terminal: Operation not permitted
I get no output from std::cout calls, even just a
std::cout << "hi" << std::endl;
Anyone able to help? I tried to google the subject and came up with a lot of similar issues, but not ones related to this particular symptom, and how to fix it. I've made sure I have the latest version of GDB, etc.
Addendum: I am using Code::Blocks as my ide.
A rebuild of my project with full commandline output gives:
-------------- Clean: Debug in DungeonCrawlerCPP ---------------
Cleaned "DungeonCrawlerCPP - Debug"
-------------- Build: Debug in DungeonCrawlerCPP ---------------
g++ -Wall -fexceptions -g -fpermissive -std=gnu++0x -Iinclude -c /home/reedja/CPPProjects/DungeonCrawlerCPP/main.cpp -o obj/Debug/main.o
g++ -Wall -fexceptions -g -fpermissive -std=gnu++0x -Iinclude -c /home/reedja/CPPProjects/DungeonCrawlerCPP/src/ActionableObject.cpp -o obj/Debug/src/ActionableObject.o
/home/reedja/CPPProjects/DungeonCrawlerCPP/src/ActionableObject.cpp:1:9: warning: #pragma once in main file [enabled by default]
g++ -Wall -fexceptions -g -fpermissive -std=gnu++0x -Iinclude -c /home/reedja/CPPProjects/DungeonCrawlerCPP/src/AppSettings.cpp -o obj/Debug/src/AppSettings.o
/home/reedja/CPPProjects/DungeonCrawlerCPP/src/AppSettings.cpp:1:9: warning: #pragma once in main file [enabled by default]
/home/reedja/CPPProjects/DungeonCrawlerCPP/src/AppSettings.cpp: In member function ‘void AppSettings::load(const char*)’:
/home/reedja/CPPProjects/DungeonCrawlerCPP/src/AppSettings.cpp:98:23: warning: statement has no effect [-Wunused-value]
/home/reedja/CPPProjects/DungeonCrawlerCPP/src/AppSettings.cpp:114:29: warning: statement has no effect [-Wunused-value]
g++ -Wall -fexceptions -g -fpermissive -std=gnu++0x -Iinclude -c /home/reedja/CPPProjects/DungeonCrawlerCPP/src/Container.cpp -o obj/Debug/src/Container.o
/home/reedja/CPPProjects/DungeonCrawlerCPP/src/Container.cpp:1:9: warning: #pragma once in main file [enabled by default]
g++ -Wall -fexceptions -g -fpermissive -std=gnu++0x -Iinclude -c /home/reedja/CPPProjects/DungeonCrawlerCPP/src/Entity.cpp -o obj/Debug/src/Entity.o
g++ -Wall -fexceptions -g -fpermissive -std=gnu++0x -Iinclude -c /home/reedja/CPPProjects/DungeonCrawlerCPP/src/Item.cpp -o obj/Debug/src/Item.o
/home/reedja/CPPProjects/DungeonCrawlerCPP/src/Item.cpp:1:9: warning: #pragma once in main file [enabled by default]
g++ -Wall -fexceptions -g -fpermissive -std=gnu++0x -Iinclude -c /home/reedja/CPPProjects/DungeonCrawlerCPP/src/Monster.cpp -o obj/Debug/src/Monster.o
/home/reedja/CPPProjects/DungeonCrawlerCPP/src/Monster.cpp:1:9: warning: #pragma once in main file [enabled by default]
g++ -Wall -fexceptions -g -fpermissive -std=gnu++0x -Iinclude -c /home/reedja/CPPProjects/DungeonCrawlerCPP/src/Player.cpp -o obj/Debug/src/Player.o
/home/reedja/CPPProjects/DungeonCrawlerCPP/src/Player.cpp: In member function ‘void Player::attackMonster(std::string)’:
/home/reedja/CPPProjects/DungeonCrawlerCPP/src/Player.cpp:36:43: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
g++ -Wall -fexceptions -g -fpermissive -std=gnu++0x -Iinclude -c /home/reedja/CPPProjects/DungeonCrawlerCPP/src/Room.cpp -o obj/Debug/src/Room.o
/home/reedja/CPPProjects/DungeonCrawlerCPP/src/Room.cpp:1:9: warning: #pragma once in main file [enabled by default]
g++ -Wall -fexceptions -g -fpermissive -std=gnu++0x -Iinclude -c /home/reedja/CPPProjects/DungeonCrawlerCPP/src/tinystr.cpp -o obj/Debug/src/tinystr.o
g++ -Wall -fexceptions -g -fpermissive -std=gnu++0x -Iinclude -c /home/reedja/CPPProjects/DungeonCrawlerCPP/src/tinyxml.cpp -o obj/Debug/src/tinyxml.o
g++ -Wall -fexceptions -g -fpermissive -std=gnu++0x -Iinclude -c /home/reedja/CPPProjects/DungeonCrawlerCPP/src/tinyxmlerror.cpp -o obj/Debug/src/tinyxmlerror.o
g++ -Wall -fexceptions -g -fpermissive -std=gnu++0x -Iinclude -c /home/reedja/CPPProjects/DungeonCrawlerCPP/src/tinyxmlparser.cpp -o obj/Debug/src/tinyxmlparser.o
g++ -o bin/Debug/DungeonCrawlerCPP obj/Debug/main.o obj/Debug/src/ActionableObject.o obj/Debug/src/AppSettings.o obj/Debug/src/Container.o obj/Debug/src/Entity.o obj/Debug/src/Item.o obj/Debug/src/Monster.o obj/Debug/src/Player.o obj/Debug/src/Room.o obj/Debug/src/tinystr.o obj/Debug/src/tinyxml.o obj/Debug/src/tinyxmlerror.o obj/Debug/src/tinyxmlparser.o
Output size is 674.11 KB
Process terminated with status 0 (0 minutes, 6 seconds)
0 errors, 9 warnings
If that helps?...
I found the answer - for some reason C::B doesn't set global -g as default, so I had no debugging symbols. I still get the weird error message, but at least I now get console output :)