I had an error unexpected during my program compilation.
(I must use standard 2011 to std::regex.)
In my MinGw cmd, I go to the folder in which my programme is, and write:
g++ -Wall -c -std=c++0x main.cpp
here every thing is ok, but after when I write:
g++ -Wall -o -std=c++0x main.exe main.o
it tell me :
g++.exe: error: main.exe: No such file or directory
WHY ?
Because you're writing the switches in the wrong order. -o requires that the destination filename be after it.
Here, you've told GCC to link main.exe and main.o into the executable -std=c++0x, and main.exe doesn't even exist yet.
g++ -Wall -o -std=c++0x main.exe main.o
# ^^^^^^^^^^^^^ ????????
Instead, tell it to link main.o into the executable main.exe, in C++0x mode:
g++ -Wall -std=c++0x -o main.exe main.o
# ^^^^^^^^^^^
Related
Hi I'm a beginner using libpqxx and libpq in c++. The problem I have is that it works all fine when I compile my code in Linux using my makefile. But once I try to compile it using mingw on Linux to have an executable on windows I can't make it work.
My makefile:
all: main.exe menu.o main.o option.o
main.exe: main.o menu.o option.o
g++ -o main.exe main.o menu.o option.o /usr/local/lib/libpqxx.a -lpq
option.o: option.cc option.hh
g++ -c option.cc
menu.o: menu.cc menu.hh
g++ -c menu.cc
main.o: main.cc menu.hh
g++ -c main.cc
clean:
rm *.o
rm *.exe
To compile with mingw I use:
x86_64-w64-mingw32-g++ -o main.exe main.o menu.o option.o /usr/local/lib/libpqxx.a /usr/lib/x86_64-linux-gnu/libpq.a
But I get the next error:
collect2: fatal error: ld terminated with signal 11 [Segmentation fault], core dumped
compilation terminated.
Good day!
I installed the fmt library in Ubuntu. Added it in my project
#include "fmt/core.h"
#include "fmt/format.h"
#include "fmt/format-inl.h"
to use fmt::format_int и fmt::format. I added library headers in several cpp files of my project. During linkage I got the mistake "multiple definition":
obj/container.o: In function fmt::v7::format_error::~format_error()': container.cpp:(.text+0x40e): multiple definition of fmt::v7::format_error::~format_error()'
obj/line.o:line.cpp:(.text+0x40e): first defined here
I've read something about this mistake. It is recommended to divide declaration and implementation in h and cpp files, to set some status to objects that causes mistake and so on. But all this recommendations imply editing of library (not my!) code!
What is wrong?
I do the following
compilation of files - one by one
g++ -std=c++11 -Wall -o obj/line.o -c /home/...//line.cpp
g++ -std=c++11 -Wall -o obj/container.o -c /home/...//container.cpp
g++ -std=c++11 -Wall -o obj/geometryObject.o -c /...//geometryObject.cpp
g++ -std=c++11 -Wall -o obj/model.o -c /home/...//model.cpp
g++ -std=c++11 -Wall -o obj/point.o -c /home/...//point.cpp
g++ -std=c++11 -Wall -o obj/main.o -c /home/...//main.cpp
Linking - error here
g++ -std=c++11 -Wall -o myapp obj/line.o obj/container.o obj/geometryObject.o obj/model.o obj/point.o obj/main.o
You shouldn't be including fmt/format-inl.h because it's an internal header. Please see the documentation for the list of public headers and what they provide.
I recently started a small project in C++. I created a simply Makefile:
output: main.o google_api.o
g++ main.o google_api.o -o output
rm *.o
clear
./output
main.o: main.cpp
g++ -c main.cpp
test.o: google_api.cpp google_api.h
g++ -c google_api.cpp
And when I compile my code I get the next error -
non-aggregate type 'vector' cannot be initialized
with an initializer list
I am check for this issue and find that I need to add -std=c++11 support to my makefile to fix the problem. I add this command to the code:
g++ -std=c++11 main.o google_api.o -o output
But this is not make any change. I would love if someone can help me to fix this problem. Thanks
change this:
main.o: main.cpp
g++ -c main.cpp
to:
main.o: main.cpp
g++ -std=c++11 -c main.cpp
You may as well use something like this as basis for your Makefile:
CXX=g++
CXXFLAGS=-g -Wall -MMD -std=c++11
LDLIBS=-lm # list libs here
output: main.o google_api.o
clean:
$(RM) *.o *.d output
-include $(wildcard *.d)
There are also similar questions on stackoverflow: Makefile c++11 support
I am trying to include a sqlite3 in my cpp project but while compilation it gives below error:
g++ -c -std=c++11 -g src/Main.cpp -I"C:/Mycode/src/DB"
-L"C:/Mycode/src/DB" -lsqlite3
g++ -g -o Main.exe Main.o Data.o SqliteApi.o -lws2_32
-L"C:/Mycode/src/DB" -lsqlite3
C:/Mycode/src/DB/sqlite3.dll: file not recognized: File format not recognized
collect2.exe: error: ld returned 1 exit status
make: ***[Mycode.exe] Error 1
I feel during final linking time it gives error.
I am using my own make file for compilation, below is the make command I am using:
DB_DIR="C:/Mycode/src/DB"
clean:
rm Main.o Main.exe
Main.exe: Main.o Data.o SqliteApi.o
g++ -g -o Main.exe Main.o Data.o SqliteApi.o -lws2_32 -L${DB_DIR} -lsqlite3
Main.o: src/Main.cpp
g++ -c -std=c++11 -g src/Main.cpp -I${DB_DIR} -lsqlite3
Data.o: src/Data.cpp
g++ -c -std=c++11 -g src/Data.cpp
SqliteApi.o: src/SqliteApi.cpp
g++ -c -std=c++11 -g src/SqliteApi.cpp
I have googled but I couldn't find any solution or suggestion for this error.
Any help will be much appreciated.
The recommended way of using the SQLite library is to compile the amalgamation source file directly into your program:
Main.exe: Main.o Data.o SqliteApi.o
g++ -g -o Main.exe Main.o Data.o SqliteApi.o sqlite3.o -lws2_32
sqlite3.o: src/sqlite3.c
gcc -c ... src/sqlite3.c
I am trying to use GLEW in a program I'm creating, but my compiler will not compile it, instead it throws a ton of errors at this line gcc -g -c glew.c -o glew.o. This is my Makefile:
MY_LIBS =
glewex: glew.o main.o glew.h
g++ main.o glew.o glew.h -o glewex $(MY_LIBS)
glew.o: glew.c
gcc -g -c glew.c -o glew.o
main.o: main.cpp
g++ -g -c main.cpp -o main.o
It simply outputs hundreds of errors that look like this:
__glewActiveTexture redeclared without dllimport attribute: previous import ignored [ -Wattributes ]
Try this:
gcc -g -DGLEW_STATIC -c glew.c -o glew.o
That should prevent DLL import/export decorations from getting added to the declarations.
You don't want to add the library source files to the compiler input of your project. You should add the library to the list of linker inputs; either statically (libglew.a) or dynamic (-lglew).
I.e. either
gcc -o … -lglew
or
gcc -o … libglew.a
When linking GLEW statically you must add -DGLEW_STATIC to the compiler options generating the compilation units (.o files)