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.
Related
I'm trying to get a C++ program that uses XWindows to build on Bash on Ubuntu on Windows. I understand that Bash on Ubuntu on Windows does not officially support graphical Linux applications, but I would like the program to build regardless if possible. I have tried to reduce my issue as much as possible, hopefully I have provided enough information.
First, I installed the libx11-dev package and the packages associated with it using the command:
sudo apt-get install libx11-dev
Second, my Makefile is the following:
CXX = g++
CXXFLAGS = -Wall -MMD -lX11
EXEC = exe
OBJECTS = main.o window.o
DEPENDS = ${OBJECTS:.o=.d}
${EXEC}: ${OBJECTS}
${CXX} ${CXXFLAGS} ${OBJECTS} -o ${EXEC}
-include ${DEPENDS}
.PHONY: clean
clean:
rm ${EXEC} ${OBJECTS} ${DEPENDS}
Third, the window.h file is the following:
#ifndef __WINDOW_H__
#define __WINDOW_H__
#include <X11/Xlib.h>
class Xwindow {
Display *d;
public:
Xwindow();
};
#endif
Fourth the window.cc file is the following:
#include "window.h"
Xwindow::Xwindow() {
d = XOpenDisplay(NULL);
}
Finally the main.cc file is the following:
#include "window.h"
int main() {
Xwindow xw();
return 0;
}
When I run my Makefile I get the following output:
g++ -Wall -MMD -lX11 -c -o main.o main.cc
g++ -Wall -MMD -lX11 -c -o window.o window.cc
g++ -Wall -MMD -lX11 main.o window.o -o exe
window.o: In function `Xwindow::Xwindow()':
window.cc:(.text+0x12): undefined reference to `XOpenDisplay'
collect2: error: ld returned 1 exit status
Makefile:8: recipe for target 'exe' failed
make: *** [exe] Error 1
Any help is appreciated.
In some environments, including Ubuntu, you need to pass -l arguments after the object files that use these libraries.
Also, -l don't belong in CXXFLAGS, they should be in LIBS which goes after ${OBJECTS}.
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 compile a game using g++ and the SFML library. It works fine on Linux, but when I try to compile on Windows, the cmd floods me with error messages that all start with "player.o:player.cpp:(.text+xxxxxx):undefined reference to _imp___..."
My makefile looks like this:
all:
main.o player.o simplefunctions.o
g++ -std=c++11 main.o player.o simplefunctions.o -o climb -L C:/SFML-2.3.1/lib -lsfml-graphics -lsfml-window -lsfml-system -lsfml-network
main.o: main.cpp
g++ -std=c++11 -c main.cpp -I C:/SFML-2.3.1/include
player.o: player.cpp
g++ -std=c++11 -c player.cpp -I C:/SFML-2.3.1/include
simplefunctions.o: simplefunctions.cpp
g++ -std=c++11 -c simplefunctions.cpp -I C:/SFML-2.3.1/include
.cpp -I C:/SFML-2.3.1/include
The only difference between this and my makefile I use for the same program on ubuntu is the -I and -L tags to include the library, which I don't need on linux since it gets included automatically. All the appropriate header files are also included in the appropriate cpp's.
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
# ^^^^^^^^^^^
I am running into problems when linking SDL_image in gcc 3 on cygwin under Windows 7.
I receive the following error:
/usr/lib/gcc/i686-pc-cygwin/4.3.4/../../../../i686-pc-cygwin/bin/ld: cannot find -lSDL_image
My makefile appears as this:
all: rabbit
rabbit: main.o rabbit.o renderer.o
g++ -o rabbit main.o rabbit.o renderer.o -lSDLmain -lSDL -lSDL_image
main.o: main.cpp rabbit.h
g++ -c main.cpp
rabbit.o: rabbit.cpp rabbit.h gameobject.h
g++ -c rabbit.cpp
renderer.o: renderer.cpp renderer.h
g++ -c renderer.cpp
clean:
rm -rf *o rabbit
I store SDL_image.dll, SDL_image.lib, jpeg.dll, libpng12-0.dll, libtiff-3.dll, and zlib1.dll in the directory with my executable. SDL_image.h is also in the correct location.
Please help, this has been at fault for a few days now!
SDL_image is not part of the core SDL distribution. It must be installed separately.
Check if you have /usr/local/lib/libSDL_image.a or the shared library installed.