This is my class code:
#include <SDL2/SDL.h>
#include "graphics.h"
/* Graphics class
* Holds all information dealing with graphics for the game
*/
Graphics::Graphics() {
SDL_CreateWindowAndRenderer(640, 480, 0, &this->_window, &this->_renderer);
SDL_SetWindowTitle(this->_window, "Cavestory");
}
Graphics::~Graphics() {
SDL_DestroyWindow(this->_window);
}
this is the error:
g++ "-LC:\\MinGW\\lib" -o cavestory-developement.exe "source\\src\\cavestory-developement.o" "source\\src\\graphics.o" -lmingw32 -lSDL2main -lSDL2
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: source\src\graphics.o: in function `ZN8GraphicsC2Ev':
C:\Users\John Park\eclipse-workspace\cavestory-developement\Debug/../source/src/graphics.cpp:10: undefined reference to `SDL_CreateWindowAndRenderer'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\John Park\eclipse-workspace\cavestory-developement\Debug/../source/src/graphics.cpp:11: undefined reference to `SDL_SetWindowTitle'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: source\src\graphics.o: in function `ZN8GraphicsD2Ev':
C:\Users\John Park\eclipse-workspace\cavestory-developement\Debug/../source/src/graphics.cpp:17: undefined reference to `SDL_DestroyWindow'
collect2.exe: error: ld returned 1 exit status
19:06:06 Build Failed. 5 errors, 0 warnings. (took 223ms)
______________________________________________________________________________________________________
not sure why SDL_SetWindowTitle is recognized (shows parameters and details about the function) when I hover over it with my mouse, but SDL_CreateWindowAndRenderer and SDL_DestroyWindow are not.
It compile fine for me on Fedora 32 x86_64, both as a native program and as a Windows program:
echo 'struct Graphics { Graphics(); ~Graphics(); SDL_Window *_window; SDL_Renderer *_renderer; } g;int main(int argc,char **argv){return 0;}' >graphics.h;g++ -o sdl2 sdl2.C -Wall -g $(pkg-config --cflags --libs sdl2);sudo dnf install mingw64-SDL2 mingw64-gcc-c++;x86_64-w64-mingw32-c++ -o sdl2.exe sdl2.C -Wall -g $(/usr/x86_64-w64-mingw32/sys-root/mingw/bin/sdl2-config --cflags --libs);(d=$PWD;cd /usr/x86_64-w64-mingw32/sys-root/mingw/bin;wine64 $d/sdl2.exe)
Related
I'm pretty sure the problem lays somewhere in my makefile, as when I make the program, the error in the title points me to line 12, the linker command. I've tinkered around for it with a while but can't seem to get anything to work. The following is my code/makefile. I am making this in mingw32.
makefile:
CXXFLAGS := -std=c++11 -Wall -Werror -g $(shell pkg-config gtkmm-3.0 --cflags)
LDLIBS = -lpthread $(shell pkg-config gtkmm-3.0 --libs)
all: test
test: sample.count
sample.count: InIT_Printer_Install_Assistant
./InIT_Printer_Install_Assistant
InIT_Printer_Install_Assistant: main.o win_home.o
g++ $(CXXFLAGS) $(LDLIBS) -o $# $^ `pkg-config gtkmm-3.0 --cflags --libs`
main.o: main.cpp win_home.h
win_home.o: win_home.cpp win_home.h
clean:
-rm -f *.o *~
spotless: clean
-rm -f InIT_Printer_Install_Assistant
main.cpp:
#include <gtkmm.h>
#include <iostream>
#include "win_home.h"
int main(int argc, char *argv[])
{
auto app = Gtk::Application::create(argc, argv, "com.InIT.PrinterApp");
HomeGUI win_home;
win_home.set_default_size(600,400);
win_home.set_title("InIT Self-Service Printer Management");
return app->run(win_home);
}
win_home.cpp:
#include "win_home.h"
HomeGUI::HomeGUI()
{
//build interface/gui
this->buildInterface();
//retrieve printers
//create printer Buttons
//register Handlers
//this->registerHandlers();
}
void HomeGUI::buildInterface()
{
//combo boxes
/*
Gtk::HBox combo_rowbox = Gtk::HBox(false, 10);
Gtk::ComboBox combobox_department = Gtk::ComboBox(false);
Gtk::ComboBox combobox_building = Gtk::ComboBox(false);
combo_rowbox.pack_start(child, false, false, padding=0)
add(combo_rowbox);
*/
return;
}
win_home.h:
#ifndef GTKMM_INIT_PRINTER_INSTALL_ASSISTANT_H
#define GTKMM_INIT_PRINTER_INSTALL_ASSISTANT_H
#include <vector>
#include <string>
#include <iostream>
#include <gtkmm.h>
class HomeGUI : public Gtk::Window
{
public:
HomeGUI();
virtual ~HomeGUI();
void buildInterface();
void registerHandlers();
//void defaultToFloorPlan();
protected:
//Signal Handlers
//Member variables
std::string m_selected_department;
std::string m_selected_building;
std::string m_selected_floor;
//Member widgets
//std::vector<Gtk::Button> m_printbuttons;
//HelpGUI m_win_help;
//UninstallGUI m_win_uninstall;
//Member logic
//ClientLogic logic;
};
#endif
Result after making:
C:\msys32\home\PrintApplication/win_home.cpp:3: undefined reference to VTT for HomeGUI'
C:\msys32\home\PrintApplication/win_home.cpp:3: undefined reference toVTT for HomeGUI'
C:\msys32\home\PrintApplication/win_home.cpp:3: undefined reference to vtable for HomeGUI'
C:\msys32\home\PrintApplication/win_home.cpp:3: undefined reference tovtable for HomeGUI'
C:\msys32\home\PrintApplication/win_home.cpp:3: undefined reference to vtable for HomeGUI'
C:\msys32\home\PrintApplication/win_home.cpp:3: undefined reference tovtable for HomeGUI'
C:\msys32\home\PrintApplication/win_home.cpp:3: undefined reference to `VTT for HomeGUI'
collect2.exe: error: ld returned 1 exit status
make: *** [Makefile:12: InIT_Printer_Install_Assistant] Error 1
If anyone can enlighten me as to why this is happening, that would be greatly appreciated.
**Note: as you can tell, I'm still a noob with makefiles, so feel free to correct me as needed when it comes to general makefile formatting.
#Unimportant's comment solved the issue. Both pure virtual and non-pure virtual functions must all have a body. Changed my win_home.h to:
#include "win_home.h"
HomeGUI::HomeGUI()
{
//build interface/gui
this->buildInterface();
//retrieve printers
//create printer Buttons
//register Handlers
//this->registerHandlers();
}
HomeGUI::~HomeGUI()
{
}
void HomeGUI::buildInterface()
{
//combo boxes
/*
Gtk::HBox combo_rowbox = Gtk::HBox(false, 10);
Gtk::ComboBox combobox_department = Gtk::ComboBox(false);
Gtk::ComboBox combobox_building = Gtk::ComboBox(false);
combo_rowbox.pack_start(child, false, false, padding=0)
add(combo_rowbox);
*/
return;
}
void HomeGUI::registerHandlers()
{
}
I am trying to compile SFML simple code:
#include <iostream>
#include <string>
#include <SFML/System.hpp>
#include <SFML/Network.hpp>
using namespace std;
int main(int argc, char* argv[])
{
sf::TcpSocket socket;
sf::Socket::Status status = socket.connect("127.0.0.1", 6000);
if (status != sf::Socket::Done)
{
// error...
}
return 0;
}
All libs and dependencies are installed:
sudo apt-get install libsfml-dev
sudo apt-get build-dep libsfml
I am using two methods:
g++ -c main.cpp
g++ -o main main.o -std=c++11 -lsfml-graphics -lsfml-window -lsfml-system
g++ -c main.cpp -I/home/x64joxer/SFML-2.4.0/include
g++ -o main main.o -L/home/x64joxer/SFML-2.4.0/lib -std=c++11 -lsfml-graphics -lsfml-window -lsfml-system
But I still have the same problem:
main.o: In function `main':
main.cpp:(.text+0x27): undefined reference to `sf::TcpSocket::TcpSocket()'
main.cpp:(.text+0x38): undefined reference to `sf::IpAddress::IpAddress(char const*)'
main.cpp:(.text+0x54): undefined reference to `sf::TcpSocket::connect(sf::IpAddress const&, unsigned short, sf::Time)'
main.o: In function `sf::TcpSocket::~TcpSocket()':
main.cpp:(.text._ZN2sf9TcpSocketD2Ev[_ZN2sf9TcpSocketD5Ev]+0x30): undefined reference to `sf::Socket::~Socket()'
main.cpp:(.text._ZN2sf9TcpSocketD2Ev[_ZN2sf9TcpSocketD5Ev]+0x56): undefined reference to `sf::Socket::~Socket()'
main.o:(.rodata._ZTIN2sf9TcpSocketE[_ZTIN2sf9TcpSocketE]+0x10): undefined reference to `typeinfo for sf::Socket'
collect2: error: ld returned 1 exit status
I read many tutorials and topics at the forum but I still do not know how too fix it.
My system is Kubntu 15.
Can anyone know how to fix it?
You are linking with graphics, system and window but not with network. Did you try adding -lsfml-network ?
I'm trying to compile a very simple program in openGL:
#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
using namespace glm;
int main()
{
if( !glfwInit() )
{
fprintf( stderr, "Failed to initialize GLFW\n");
return -1;
}
glfwWindowHint(GLFW_SAMPLES, 4); // 4x antialiasing
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // Use OpenGL 3.X
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); // Use openGL X.3
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// Open a window and create OpenGL context
GLFWwindow* window; // May be needed to make it global
window = glfwCreateWindow(1024, 768, "Tutorial 01", NULL, NULL);
if(window == NULL)
{
fprintf(stderr, "Failed to pen GLFW window. If you have Intel GPU they are not 3.3 compatible. Try the 2.1 version of the tutorial.\n");
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window); // Initialize GLEW
glewExperimental=true; // Needed in core profile
if(glewInit() != GLEW_OK)
{
fprintf(stderr, "Failed to initialize GLEW.\n");
return -1;
}
}
However when i try to compile it with g++ i'm getting the following errors:
In function `main':
playground.cpp:(.text+0x9): undefined reference to `glfwInit'
playground.cpp:(.text+0x49): undefined reference to `glfwWindowHint'
playground.cpp:(.text+0x58): undefined reference to `glfwWindowHint'
playground.cpp:(.text+0x67): undefined reference to `glfwWindowHint'
playground.cpp:(.text+0x76): undefined reference to `glfwWindowHint'
playground.cpp:(.text+0x85): undefined reference to `glfwWindowHint'
playground.cpp:(.text+0xa4): undefined reference to `glfwCreateWindow'
playground.cpp:(.text+0xd2): undefined reference to `glfwTerminate'
playground.cpp:(.text+0xe5): undefined reference to `glfwMakeContextCurrent'
playground.cpp:(.text+0xeb): undefined reference to `glewExperimental'
playground.cpp:(.text+0xf1): undefined reference to `glewInit'
collect2: error: ld returned 1 exit status
I've found some posts to this specific problem and the solution seems to be to pass the required libraries as arguments to g++. However, when i do that, the problem still persists.
This is how i compile the code:
g++ -lglfw3 -pthread -lGLEW -lGLU -lGL -lrt -lXrandr -lXxf86vm -lXi -lXinerama -lX11 -o openGLWindow openGLWindow.cpp
Any help would be appreciated...
when i try to compile it with g++ i'm getting the following errors:
No, your compilation is just fine. You are getting link errors, not compile errors.
The reason for your link errors is that your link command line is completely backwards. Try this instead:
g++ -pthread -o openGLWindow openGLWindow.cpp -lglfw3 -lGLEW -lGLU -lGL -lXrandr -lXxf86vm -lXi -lXinerama -lX11 -lrt -ldl
I am not sure the order of libraries above is correct, but it's certainly better than what you have. The order of sources, object files, and libraries on command line matters.
I use this command to build and run my application in a terminal. (move in the application directory with cd exemple/c)
gcc -o main main.c -I/usr/include -lglfw -lGL -GL -glut; sleep 0.1;./main
I see where my applications was by this command in a shell/prompt/terminal
pkg-config --libs --cflags --debug glfw3
Possible dup of this or this, but even after trying to dig through the answers for a while, I couldn't resolve this.
While trying to compile following makefile,
all: test
test: constants.h Point.h Point.cpp line_t.h line_t.cpp drawing_t.h drawing_t.cpp clipper_t.h clipper_t.cpp main.cpp
g++ -o test Point.cpp line_t.cpp drawing_t.cpp clipper_t.cpp main.cpp -lglut
I get an error:
g++ -o test Point.cpp line_t.cpp drawing_t.cpp clipper_t.cpp main.cpp
-lglut /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crt1.o: In function _start': (.text+0x18): undefined reference tomain'
collect2: ld returned 1 exit status make: *** [test] Error 1
I am new at Makefile. I guess, I am missing something too obvious.
Apparently none your files define a function with the signature
int main();
or
int main(int argc, char *argv[]);
I'm trying to compile the following sample code available at XERCES site:
#include <xercesc/util/PlatformUtils.hpp>
// Other include files, declarations, and non-Xerces-C++ initializations.
XERCES_CPP_NAMESPACE_USE
int main(int argc, char* argv[])
{
try {
XMLPlatformUtils::Initialize();
}
catch (const XMLException& toCatch) {
// Do your failure processing here
return 1;
}
// Do your actual work with Xerces-C++ here.
XMLPlatformUtils::Terminate();
// Other terminations and cleanup.
return 0;
}
with,
g++ -g -Wall -pedantic -L/usr/lib -lxerces-c -o xercesTest xercesTest.cpp
giving me the following linking error:
/tmp/ccYIHCfR.o: In function `main':
/home/cjmv/temp/xercesTest.cpp:8: undefined reference to `xercesc_2_8::XMLUni::fgXercescDefaultLocale'
/home/cjmv/temp/xercesTest.cpp:8: undefined reference to `xercesc_2_8::XMLPlatformUtils::Initialize(char const*, char const*, xercesc_2_8::PanicHandler*, xercesc_2_8::MemoryManager*, bool)'
/home/cjmv/temp/xercesTest.cpp:18: undefined reference to `xercesc_2_8::XMLPlatformUtils::Terminate()'
/tmp/ccYIHCfR.o:(.gcc_except_table+0x10): undefined reference to `typeinfo for xercesc_2_8::XMLException'
collect2: ld returned 1 exit status
I've installed xerces-c28 and xerces-c2-dev through aptitude on my ubuntu-server 12.04
Any help would be appreciated.
Put the library last on the command line:
g++ -g -Wall -pedantic -L/usr/lib -o xercesTest xercesTest.cpp -lxerces-c
include the lib path of xerces:
try this
g++ -I/<xerces-c 2.8.0 path>/include -c xercesTest.cpp
g++ -L/<xerces-c 2.8.0 path>/lib -lxerces-c xercesTest.o