I wrote a C++ software using GTK2 library for UI.
It'a simple software that analyze a map coded on XML file to calculate the shortest path between two points and draw it on the image (I'm using Cairo library for this).
The compilation (with makefile) gave no errors but when I execute the program the window appears empty.If I try to compile with debug option (-g) and execute the program with ddd for debugging it returnS "no debugging symbols found".
makefile is
CXXFLAGS += -Wall `pkg-config --cflags --libs gtk+-2.0`
ObjectsMy = main.o interface.o callback.o map.o path.o draw.o
NaViGaToR: DependenciesMy $(ObjectsMy)
g++ -g $(ObjectsMy) -o NaViGaToR `pkg-config gtk+-2.0 --cflags --libs`
DependenciesMy:
g++ -MM main.cpp interface.cpp callback.cpp map.cpp path.cpp draw.cpp
> DependenciesMy
-include DependenciesMy
.PHONY: clean cleanall
clean:
rm $(ObjectsMy) DependenciesMy
rm $ map.png
cleanall:
rm $(ObjectsMy) NaViGaToR DependenciesMy
rm $ map.png
Can you see some error in this?
You are passing -g to the linker and not to the compiler. If there's no debugging info in the object files there won't be any in the executable. You need to add -g to the CXXFLAGS.
Related
I have been trying to set up my coding environment for GUI development in c++ recently, with little success. I use Manjaro Linux with Visual Studio Code, but for some reason, I always seem to get include errors when including files that I know are there.
Most recently, I tried to set up gtkmm-4.0 by installing the package and the documentation. I double checked in /usr/include/ to ensure the packages were all present, but I still am getting include errors:
cannot open source file "gtkmm.h" and
gtkmm.h:No such file or directory
At this point, all the code I have is:
#include <gtkmm.h>
#include <iostream>
int main(int argc, char* argv[]){
return 0;
}
Makefile:
exec = game.out
sources = $(wildcard src/*.cpp)
objects = $(sources:.cpp=.o)
flags = -g $(shell pkg-config gtkmm-4.0 --cflags)
libs = $(shell pkg-config gtkmm-4.0 --libs)
$(exec): $(objects)
g++ $(objects) $(flags) -o $(exec) $(libs)
%.o: %.cpp include/%.h
g++ -c $(flags) $< -o $#
install:
make
cp ./game.out /usr/local/bin/game
clean:
-rm *.out
-rm *.o
-rm src/*.o
I have scoured the internet for answers, but everything I found was either for a different os/environment or just didn't
#Galik and #John helped me solve this!
What I had to do was use g++ src/main.cpp -o main $(pkg-config gtkmm-4.0 --cflags --libs) to compile my code, then run the executable.
Thank you both for your help and guidance!!
You need to install pkg-configand add this to the compiler flags in your Makefile:
flags = -g $(shell pkg-config gtkmm-2.4 --cflags)
libs = $(shell pkg-config gtkmm-2.4 --libs)
# ...
$(exec): $(objects)
g++ $(objects) $(flags) -o $(exec) $(libs)
The tool pkg-config has a database of the correct paths for supporting libraries.
Depending on your version if gtkmm, you may need to substitute gtkmm-3.0, if you have version 3.0.
I have an SDL game I have been working on as my first somewhat real project. I decided to introduce Box2D physics as I was not happy with the collision detection. So I installed it to /usr/local/lib/Box2D and in the folder is Box2D.h and supporting folders. I am using MacVim to code on OSX 10.9.2 to develop, and clang++ compiler from the command line.
In my game code I am just trying to create a simple world to test things out:
#include <Box2D/Box2D.h>
.......
world = new b2World(b2Vec2(0.0,9.81));
My make command finds the library, but errors out trying to build.
$ make clean && make
rm -rf obj bin
clang++ -Wall -c -std=c++11 -I/usr/local/lib src/Ball.cpp -o obj/Ball.o
clang++ -Wall -c -std=c++11 -I/usr/local/lib src/Game.cpp -o obj/Game.o
clang++ -Wall -c -std=c++11 -I/usr/local/lib src/Paddle.cpp -o obj/Paddle.o
clang++ -Wall -c -std=c++11 -I/usr/local/lib src/TextureManager.cpp -o obj/TextureManager.o
clang++ -Wall -c -std=c++11 -I/usr/local/lib src/main.cpp -o obj/main.o
clang++ -framework SDL2 -framework SDL2_image -F /Library/Frameworks -L/usr/local/lib/Box2D obj/Ball.o obj/Game.o obj/Paddle.o obj/TextureManager.o obj/main.o -o bin/game
Undefined symbols for architecture x86_64:
"b2World::b2World(b2Vec2 const&)", referenced from:
Game::init() in Game.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [game] Error 1
And here is my Makefile. Box2D is in /usr/local/lib/Box2D/Box2D.h. I am pretty sure my issue is somewhere in the Makefile.
CXX = clang++
CXXFLAGS = -Wall -c -std=c++11 -I/usr/local/lib
SDL = -framework SDL2 -framework SDL2_image
LDFLAGS = $(SDL) -F /Library/Frameworks -L/usr/local/lib/Box2D
SRC_DIR = src
SOURCES = $(wildcard $(SRC_DIR)/*.cpp)
OBJ_DIR = obj
OBJECTS = $(subst $(SRC_DIR)/, $(OBJ_DIR)/, $(patsubst %.cpp, %.o, $(SOURCES)))
#$(warning $(OBJECTS))
BIN_DIR = bin
EXE = game
# run these no matter what
.PHONY: all clean run
all: $(EXE)
$(EXE): $(OBJECTS)
#mkdir -p $(BIN_DIR)
$(CXX) $(LDFLAGS) $(OBJECTS) -o $(BIN_DIR)/$(EXE)
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
#mkdir -p $(OBJ_DIR)
$(CXX) $(CXXFLAGS) $< -o $#
clean:
rm -rf obj bin
run:
./$(BIN_DIR)/$(EXE)
It does not appear that you ever actually link the Box2D library anywhere? You use -L to specify directories to search while linking, but I don't see a -l option to actually link the Box2D library (whatever it's called).
Your output line seems to bear this out:
clang++ -framework SDL2 -framework SDL2_image -F /Library/Frameworks -L/usr/local/lib/Box2D obj/Ball.o obj/Game.o obj/Paddle.o obj/TextureManager.o obj/main.o -o bin/game
You need to get -lbox2d (or whatever the correct name for the Box2D library is) in there.
I am trying to compile a program consisting of two source files:
wildcardtrie.h, wildcardtrie.cpp
using a Makefile. However, when I run GDB to debug, I get the following error:
Reading symbols from /home/meric/Documents/Random/SectionLeading/wildcardtrie...(no debugging symbols found)...done.
I have tried a number of different compiler flags, none of which worked. The thing that perplexes me is that I have used a nearly identical Makefile in other programs and missing symbols has never been a problem. I have included the Makefile below:
CC=g++
CFLAGS = -g -ggdb g++ -O0 -Wall -Wfloat-equal -Wtype-limits -Wpointer-arith -Wlogical- op -fno-diagnostics-show-option
LDFLAGS = -g -ggdb -std=c++0x
programs = wildcardtrie
all : $(programs)
clean:
rm -f $(programs) core *.o
.PHONY: clean all
I have tried removing '-g' and '-ggdb' in the compiler and linker flags, but nothing seems to work. When I call 'make', I get the following output on the terminal:
g++ -c -o wildcardtrie.o wildcardtrie.cpp
g++ -g -ggdb -std=c++0x wildcardtrie.o -o wildcardtrie
Any help would be greatly appreciated!
g++ -c -o wildcardtrie.o wildcardtrie.cpp
This clearly shows that -g is not on your compile line (which is exactly the cause of your problem).
To get -g there, either add it to CXXFLAGS (this is the preferred solution), or just write the compile rule explicitly (instead of relying on built-in make rule):
wildcardtrie.o: wildcardtrie.cpp
$(CC) $(CFLAGS) -o wildcardtrie.o wildcardtrie.cpp
I have a problem with getting compiled an wxWidget-application. I have installed the latest version of the library as follows:
set arch_flags="-arch x86_64 "
./configure -with-osx_cocoa --disable-shared --disable-compat24 --enable-unicode --enable-universal-binary CFLAGS="$arch_flags" CXXFLAGS="$arch_flags" CPPFLAGS="$arch_flags" LDFLAGS="$arch_flags" OBJCFLAGS="$arch_flags" OBJCXXFLAGS="$arch_flags"
sudo make install
I'am trying to compile a simple hello-world example with:
WXWIDGETS = -I/usr/local/include/wx-2.9/
CXXFLAGS = -O2 -g -Wall -Wextra -fmessage-length=0
CXX = $(shell wx-config --cxx)
PROGRAM = wxProjectExample
OBJECTS = $(PROGRAM).o
# implementation
.SUFFIXES: .o .cpp
.cpp.o :
$(CXX) -c `wx-config --static=yes --libs` `wx-config --static=yes --cxxflags` -o $# $<
all: $(PROGRAM)
$(PROGRAM): $(OBJECTS)
$(CXX) -o $(PROGRAM) $(OBJECTS) `wx-config --libs`
clean:
rm -f *.o $(PROGRAM)
But the compilation fails while linking with:
ld: warning: in /System/Library/Frameworks//QuickTime.framework/QuickTime, missing required architecture x86_64 in file
ld: warning: in /usr/lib/libwx_macud-2.8.dylib, missing required architecture x86_64 in file
Undefined symbols:
"wxWindowBase::DoSetVirtualSize(int, int)", referenced from:
vtable for MyFramein wxProjectExample.o
Where could be a problem or have somebody had similar problems with this framework?
Thx.
PS
System: SnowLeopard (64 bit) 10.6.5. with an intel proc, gcc 4.2.
i fixed this problem by adding the path to the new wx-binaries to PATH
$ export PATH=/usr/local/Cellar/wxmac/2.8.11/bin:$PATH
i'm using brew to install wxmac.
I'm surprised that you have libwx_xxx in /usr/lib when the default installation prefix is /usr/local. Are you sure you don't have multiple incompatible libraries versions on your system?
Also, when using static linking the libraries containing the dependencies of your code must come after the object file referencing them so the wx-config --libs part should be at the end of your rule.
I am using Ubuntu for one of the first times and eclipse's debugger has given me more trouble than I can deal with. For the moment I just want to try to figure out how to get the "Cannot find bounds of current function" to stop so I can see where my flow of control goes awry.
I know this is a vague question, but I'm willing to quickly supply any sort of information necessary. I've been googling info for about 2 hours and switching on and off different things to no avail.
I'm using Version: 3.4.1 (I believe the newest one)
Also, my breakpoints won't always works (probably about a 25% success rate) even when I set them before the build. My cout<< or printf also can't print before the programs blows up. This makes me think it's some sort of concurrent process that is outpacing the debugger, but I have no idea how to fix this.
I would greatly appreciate any help. I'll be around.
Not an unheard-of problem
I suppose you can confirm that:
all the shared libraries are compiled with -g flag (debug) ?
and the output application binary file seems to be ok because it runs correctly in command line ?
you are not compiling with some framwework (like Qt4) which would require qmake to be run to generate the project file to which you add "CONFIG += qt debug" ?
you have no warning of any kind during the build ? (like this "Clock skew detected" message)
The point of all this is:
Somewhere, one of the libs or your own program do not have "debug" information in it.
The -g flag can be set directly in the makefile (and is not particularly dependent of the OS in this instance).
Example (not targeted for Linux)
CXX = g++
CXXFLAGS = -O2 -Wno-deprecated -g
DEFINES = -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -DLITTLE_ENDIAN
##########################
COMPILE=$(CXX) $(CXXFLAGS) $(DEFINES)
LINK=$(CXX)
UNRAR_OBJ=filestr.o recvol.o rs.o scantree.o
OBJECTS=rar.o strlist.o strfn.o pathfn.o
.cpp.o:
$(COMPILE) -D$(WHAT) -c -g $<
all: unrar
clean:
#rm -f *.o *.bak *~
unrar: WHAT=UNRAR
unrar: $(OBJECTS) $(UNRAR_OBJ)
#rm -f makeunrar
$(LINK) -Wl,-s -g -o unrar $(LDFLAGS) $(OBJECTS)
$(UNRAR_OBJ) $(LIBS)
sfx: WHAT=SFX_MODULE
sfx: $(OBJECTS)
#rm -f default.sfx
$(LINK) -Wl,-s -g -o default.sfx $(LDFLAGS)
$(OBJECTS) -DSFX_MODULE
g++ -O2 -Wno-deprecated -g -D_FILE_OFFSET_BITS=64
-D_LARGEFILE_SOURCE -DLITTLE_ENDIAN -DUNRAR -c -g
rar.cpp
[...]
g++ -Wl,-s -g -o unrar rar.o strlist.o ...
Here, that makefile contains a huge trap:
g++ -Wl,-s -o unrar rar.o strlist.o ...
-s stands for "strip" meaning all the debug informations generated before are lost in the final output. So do check also your link options.