First of all sorry for my bad english.
i am trying to link raylib.
Windows 10
PreMake version 5.0
g++ version 8.1.0
Directory
// premake5.lua
workspace "foo"
architecture "x64"
configurations {"Debug","Release"}
outputdir = "%{cfg.buildcfg}-%{cfg.architecture}-%{cfg.system}"
project "foo"
location "./build/"
kind "ConsoleApp"
language "C++"
targetdir "./build/%{cfg.buildcfg}"
files { "./src/**.cpp",
"./src/**.c",
"./dependencies/**.h"
}
includedirs {"./dependencies/**"}
links{"raylib"}
libdirs{"./dependencies/**"}
filter "configurations:Debug"
defines { "DEBUG" }
symbols "On"
filter "configurations:Release"
defines { "NDEBUG" }
optimize "On
"```
// main.cpp
#include <iostream>
#include <raylib.h>
int main(){
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
SetTargetFPS(60);
while (!WindowShouldClose())
{
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
EndDrawing();
//----------------------------------------------------------------------------------
}
CloseWindow();
return 0;
}```
error message:
Linking Mew
../dependencies/raylib/lib/libraylib.a(core.o):core.c:(.text+0x14dcd): undefined reference to timeEndPeriod' ../dependencies/raylib/lib/libraylib.a(core.o):core.c:(.text+0x167ca): undefined reference to timeBeginPeriod'
../dependencies/raylib/lib/libraylib.a(rglfw.o):rglfw.c:(.text+0x16fa): undefined reference to __imp_CreateRectRgn' ../dependencies/raylib/lib/libraylib.a(rglfw.o):rglfw.c:(.text+0x1736): undefined reference to __imp_DeleteObject'
../dependencies/raylib/lib/libraylib.a(rglfw.o):rglfw.c:(.text+0x1791): undefined reference to __imp_SwapBuffers' ../dependencies/raylib/lib/libraylib.a(rglfw.o):rglfw.c:(.text+0x21ce): undefined reference to __imp_GetDeviceCaps'
../dependencies/raylib/lib/libraylib.a(rglfw.o):rglfw.c:(.text+0x27ff): undefined reference to __imp_CreateDCW' ../dependencies/raylib/lib/libraylib.a(rglfw.o):rglfw.c:(.text+0x2813): undefined reference to __imp_GetDeviceGammaRamp'
../dependencies/raylib/lib/libraylib.a(rglfw.o):rglfw.c:(.text+0x281c): undefined reference to __imp_DeleteDC' ../dependencies/raylib/lib/libraylib.a(rglfw.o):rglfw.c:(.text+0x6154): undefined reference to __imp_CreateDCW'
../dependencies/raylib/lib/libraylib.a(rglfw.o):rglfw.c:(.text+0x6183): undefined reference to __imp_GetDeviceCaps' ../dependencies/raylib/lib/libraylib.a(rglfw.o):rglfw.c:(.text+0x619c): undefined reference to __imp_DeleteDC'
../dependencies/raylib/lib/libraylib.a(rglfw.o):rglfw.c:(.text+0x6308): undefined reference to __imp_GetDeviceCaps' ../dependencies/raylib/lib/libraylib.a(rglfw.o):rglfw.c:(.text+0x633e): undefined reference to __imp_GetDeviceCaps'
../dependencies/raylib/lib/libraylib.a(rglfw.o):rglfw.c:(.text+0x6539): undefined reference to __imp_CreateDIBSection' ../dependencies/raylib/lib/libraylib.a(rglfw.o):rglfw.c:(.text+0x6573): undefined reference to __imp_CreateBitmap'
../dependencies/raylib/lib/libraylib.a(rglfw.o):rglfw.c:(.text+0x660b): undefined reference to __imp_DeleteObject' ../dependencies/raylib/lib/libraylib.a(rglfw.o):rglfw.c:(.text+0x6660): undefined reference to __imp_DeleteObject'
../dependencies/raylib/lib/libraylib.a(rglfw.o):rglfw.c:(.text+0x7e89): undefined reference to __imp_CreateDCW' ../dependencies/raylib/lib/libraylib.a(rglfw.o):rglfw.c:(.text+0x7e98): undefined reference to __imp_SetDeviceGammaRamp'
../dependencies/raylib/lib/libraylib.a(rglfw.o):rglfw.c:(.text+0x7ea1): undefined reference to __imp_DeleteDC' ../dependencies/raylib/lib/libraylib.a(rglfw.o):rglfw.c:(.text+0xdcb2): undefined reference to __imp_ChoosePixelFormat'
../dependencies/raylib/lib/libraylib.a(rglfw.o):rglfw.c:(.text+0xdcc0): undefined reference to __imp_SetPixelFormat' ../dependencies/raylib/lib/libraylib.a(rglfw.o):rglfw.c:(.text+0xe159): undefined reference to __imp_DescribePixelFormat'
../dependencies/raylib/lib/libraylib.a(rglfw.o):rglfw.c:(.text+0xe251): undefined reference to __imp_DescribePixelFormat' ../dependencies/raylib/lib/libraylib.a(rglfw.o):rglfw.c:(.text+0xe61d): undefined reference to __imp_DescribePixelFormat'
../dependencies/raylib/lib/libraylib.a(rglfw.o):rglfw.c:(.text+0xe63c): undefined reference to `__imp_SetPixelFormat'
collect2.exe: error: ld returned 1 exit
status
mingw32-make: *** [Makefile:78: Debug/Mew.exe] Error 1
Thank you and also forgive me for my English.
a little bit late but I'll try. While compiling on Windows you need to add link libraries dependencies explicitely, especially the windows ones.
What you described are link errors. To solve the linkage problem, you have to add to link dependencies some libraries: opengl32.lib, gdi32.lib, user32.lib, ole32.lib, and optional: [netapi32.lib, Wininet.lib]
The __imp_SetPixelFormat, __imp_DescribePixelFormat, __imp_ChoosePixelFormat are defined in gdi32.lib
The __imp_SetDeviceGammaRamp is defined in opengl.lib
The __imp_DeleteObject, __imp_CreateDCW, __imp_SwapBuffers, __imp_DeleteDC are defined in the user32.lib
Hope it is useful.
PS: for runtime, make sure you have the correct redistributable (dlls).
Related
I'm trying to call Matlab function from C++ (for NS-3) in Eclipse IDE on Ubuntu 18.04. I used Matlab Library Compiler to compile the .m file into a C++ Shared Library. How do I call the function correctly?
The corresponding MATLAB Runtime has been installed and configured. At first it can't find "mclmcrrt.h", I copied the /usr/local/MATLAB/R2018b/extern/include folder and changed the library header to include "./include/mclmcrrt.h". Then the IDE can find the header files correctly.
A C++ script to test the library as follows:
/* C = A+B */
#include <iostream>
#include "libtestAdd.h"
using namespace std;
int main(){
double A[] = {1};
double B[] = {2};
int nargout = 1;
mwArray input_A (1,1,mxDOUBLE_CLASS,mxREAL);
input_A.SetData(M,1);
mwArray input_B (1,1,mxDOUBLE_CLASS,mxREAL);
input_B.SetData(K,1);
mwArray C (1,1,mxDOUBLE_CLASS,mxREAL);
if (!mclInitializeApplication(NULL,0)){
std::cerr << "Could not initialize the application properly."
<< std::endl;
return -1;
}
libtestAddInitialize();
testAdd(nargout, C, input_A, input_B);
libtestAddTerminate();
return 1;
}
The Matlab function is C=A+B.
The .m file has been compiled into a C++ Shared Library ("libtestAdd.so" and "libtestAdd.h"). The C++ script try to call the "testAdd" function from the library.
Matlab Runtime has been correctly installed. /etc/profile has been changed to export the follows path to LD_LIBRARY_PATH environment variable:
/usr/local/MATLAB/MATLAB_Runtime/v95/runtime/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v95/bin/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v95/sys/os/glnxa64
The error messages as follows:
~/Desktop/libtestAdd/for_testing$ cd "/home/csrl/Desktop/libtestAdd/for_testing/" && g++ main.cpp -o main && "/home/csrl/Desktop/libtestAdd/for_testing/"main
/tmp/ccyFn7iq.o: In function `main':
main.cpp:(.text+0xde): undefined reference to `libtestAddInitialize'
main.cpp:(.text+0xf4): undefined reference to `testAdd(int, mwArray&, mwArray const&, mwArray const&)'
main.cpp:(.text+0xf9): undefined reference to `libtestAddTerminate'
/tmp/ccyFn7iq.o: In function `mwException::mwException()':
main.cpp:(.text._ZN11mwExceptionC2Ev[_ZN11mwExceptionC5Ev]+0x46): undefined reference to `mclcppCreateError_proxy'
/tmp/ccyFn7iq.o: In function `mwException::mwException(char const*)':
main.cpp:(.text._ZN11mwExceptionC2EPKc[_ZN11mwExceptionC5EPKc]+0x5a): undefined reference to `mclcppCreateError_proxy'
/tmp/ccyFn7iq.o: In function `mwException::mwException(error_info*, bool)':
main.cpp:(.text._ZN11mwExceptionC2EP10error_infob[_ZN11mwExceptionC5EP10error_infob]+0x61): undefined reference to `ref_count_obj_addref_proxy'
main.cpp:(.text._ZN11mwExceptionC2EP10error_infob[_ZN11mwExceptionC5EP10error_infob]+0x7a): undefined reference to `mclcppCreateError_proxy'
/tmp/ccyFn7iq.o: In function `mwException::~mwException()':
main.cpp:(.text._ZN11mwExceptionD2Ev[_ZN11mwExceptionD5Ev]+0x36): undefined reference to `ref_count_obj_release_proxy'
/tmp/ccyFn7iq.o: In function `mwException::what() const':
main.cpp:(.text._ZNK11mwException4whatEv[_ZNK11mwException4whatEv]+0x25): undefined reference to `error_info_get_message_proxy'
/tmp/ccyFn7iq.o: In function `mwException::raise_error()':
main.cpp:(.text._ZN11mwException11raise_errorEv[_ZN11mwException11raise_errorEv]+0x2a): undefined reference to `mclcppGetLastError_proxy'
/tmp/ccyFn7iq.o: In function `mwArray::mwArray(unsigned long, unsigned long, mxClassID, mxComplexity)':
main.cpp:(.text._ZN7mwArrayC2Emm9mxClassID12mxComplexity[_ZN7mwArrayC5Emm9mxClassID12mxComplexity]+0x52): undefined reference to `mclGetMatrix_proxy'
/tmp/ccyFn7iq.o: In function `mwArray::~mwArray()':
main.cpp:(.text._ZN7mwArrayD2Ev[_ZN7mwArrayD5Ev]+0x26): undefined reference to `ref_count_obj_release_proxy'
/tmp/ccyFn7iq.o: In function `mwArray::SetData(double*, unsigned long)':
main.cpp:(.text._ZN7mwArray7SetDataEPdm[_ZN7mwArray7SetDataEPdm]+0x2b): undefined reference to `array_ref_set_numeric_mxDouble_proxy'
collect2: error: ld returned 1 exit status
You need to link with the .so file. Add it to the end of your compile command.
Trying to use Boost Python, but getting linkage issues.
Code, hello.cpp:
#include <boost/python.hpp>
char const* greet() {
return "hellow, world";
}
int main() {
return 0;
}
BOOST_PYTHON_MODULE(hello_ext) {
using namespace boost::python;
def("greet", greet);
}
Compiling with:
g++ hello.cpp -L/usr/lib/x86_64-linux-gnu/ -I/usr/include/python3.5/ -lboost_python /usr/lib/x86_64-linux-gnu/libpython3.5m.so -lboost_system
Getting the following linkage errors:
tmp/ccJ8ST4B.o: In function `PyInit_hello_ext':
hello.cpp:(.text+0x94): undefined reference to `boost::python::detail::init_module(PyModuleDef&, void (*)())'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `PyString_Size'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `PyUnicodeUCS4_FromEncodedObject'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `PyFile_FromString'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `PyString_Type'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `PyInt_Type'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `PyString_FromString'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `PyUnicodeUCS4_AsWideChar'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `PyString_FromStringAndSize'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `Py_InitModule4_64'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `PyString_FromFormat'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `PyNumber_Divide'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `PyNumber_InPlaceDivide'
/usr/lib/x86_64-linux-gnu//libboost_python.so: undefined reference to `PyInt_AsLong'
Any ideas?
Here while compiling give proper, exact and ordered path for libraries. Please use below command and try, If it doesn't work set LD_LIBRARY_PATH(set in program dir path only) to program directory path. This will link all the required library to your program directory.
g++ -I/usr/include/python3.5/ /usr/lib/x86_64-linux-gnu/libpython3.5m.so -L/usr/lib/x86_64-linux-gnu/ -lboost_python -lboost_system hello.cpp -o hello
If above line do not work
export LD_LIBRARY_PATH=/program_path:$LD_LIBRARY_PATH
I am trying to get OGDF working to see if it is suitable for my project, but I am having trouble with a sample program.
I am trying to compile this example program:
#include <ogdf/basic/Graph.h>
#include <ogdf/basic/graph_generators.h>
#include <ogdf/layered/DfsAcyclicSubgraph.h>
using namespace ogdf;
int main()
{
Graph G;
randomSimpleGraph(G, 10, 20);
DfsAcyclicSubgraph DAS;
DAS.callAndReverse(G);
G.writeGML("test.gml");
return 0;
}
using this command:
$g++ -pthread -I ./OGDF/ -L ./OGDF/_release/ -lOGDF test2.cpp
But I get the following error
/tmp/ccbpkfdt.o: In function `main':
test2.cpp:(.text+0x12): undefined reference to `ogdf::Graph::Graph()'
test2.cpp:(.text+0x2e): undefined reference to `ogdf::randomSimpleGraph(ogdf::Graph&, int, int)'
test2.cpp:(.text+0x4e): undefined reference to `ogdf::AcyclicSubgraphModule::callAndReverse(ogdf::Graph&)'
test2.cpp:(.text+0x62): undefined reference to `ogdf::Graph::writeGML(char const*) const'
test2.cpp:(.text+0x7f): undefined reference to `ogdf::Graph::~Graph()'
test2.cpp:(.text+0xa1): undefined reference to `ogdf::Graph::~Graph()'
/tmp/ccbpkfdt.o: In function `__static_initialization_and_destruction_0(int, int)':
test2.cpp:(.text+0xfb): undefined reference to `ogdf::Initialization::Initialization()'
test2.cpp:(.text+0x112): undefined reference to `ogdf::Initialization::~Initialization()'
/tmp/ccbpkfdt.o: In function `ogdf::DfsAcyclicSubgraph::DfsAcyclicSubgraph()':
test2.cpp:(.text._ZN4ogdf18DfsAcyclicSubgraphC2Ev[_ZN4ogdf18DfsAcyclicSubgraphC5Ev]+0x16): undefined reference to `vtable for ogdf::DfsAcyclicSubgraph'
/tmp/ccbpkfdt.o: In function `ogdf::DfsAcyclicSubgraph::~DfsAcyclicSubgraph()':
test2.cpp:(.text._ZN4ogdf18DfsAcyclicSubgraphD2Ev[_ZN4ogdf18DfsAcyclicSubgraphD5Ev]+0xb): undefined reference to `vtable for ogdf::DfsAcyclicSubgraph'
collect2: error: ld returned 1 exit status
I tried compiling hello world, with an include from OGDF, and I still got:
undefined reference to `ogdf::Initialization::Initialization()'
I think I am not linking properly or something?
You have to be very careful in which order you type stuff when linking with a library.
Try putting test2.cpp before -lOGDF instead, like this:
g++ -pthread -I ./OGDF/ -L ./OGDF/_release/ test2.cpp -lOGDF
You must build your program using the -DOGDF_DLL when using OGDF as a shared library.
See here: http://www.ogdf.net/doku.php/tech:defines
I'm lost here. I've been compiling my program successfully on LLVM on my Mac, but when I went to a Linux server and attempted to use g++ to compile, I got a boat load of linker errors.
Here's an excerpt:
/tmp/ccGbgd6T.o: In function `Scene::setBackgroundImage(String)':
Project.cpp:(.text+0x166): undefined reference to `Graph_lib::Image::Image(Point, String, Graph_lib::Suffix::Encoding)'
/tmp/ccGbgd6T.o: In function `Graph_lib::Window::~Window()':
Project.cpp:(.text._ZN9Graph_lib6WindowD2Ev[_ZN9Graph_lib6WindowD5Ev]+0xc): undefined reference to `vtable for Graph_lib::Window'
/tmp/ccGbgd6T.o: In function `Graph_lib::Shape::~Shape()':
Project.cpp:(.text._ZN9Graph_lib5ShapeD2Ev[_ZN9Graph_lib5ShapeD5Ev]+0xb): undefined reference to `vtable for Graph_lib::Shape'
/tmp/ccGbgd6T.o: In function `Graph_lib::Text::Text(Point, String const&)':
Project.cpp:(.text._ZN9Graph_lib4TextC2E5PointRK6String[_ZN9Graph_lib4TextC5E5PointRK6String]+0xe): undefined reference to `Graph_lib::Shape::Shape()'
Project.cpp:(.text._ZN9Graph_lib4TextC2E5PointRK6String[_ZN9Graph_lib4TextC5E5PointRK6String]+0x17): undefined reference to `vtable for Graph_lib::Text'
Project.cpp:(.text._ZN9Graph_lib4TextC2E5PointRK6String[_ZN9Graph_lib4TextC5E5PointRK6String]+0x67): undefined reference to `Graph_lib::Shape::add(Point)'
/tmp/ccGbgd6T.o: In function `Graph_lib::Button::Button(Point, int, int, String const&, void (*)(void*, void*))':
Project.cpp:(.text._ZN9Graph_lib6ButtonC2E5PointiiRK6StringPFvPvS5_E[_ZN9Graph_lib6ButtonC5E5PointiiRK6StringPFvPvS5_E]+0x40): undefined reference to `vtable for Graph_lib::Button'
This scared me, but then I noticed that all the errors are coming from the same class: Graph_lib. Here's an extremely cut out version of what Graph.h looks like: (note, this is not my class)
#ifndef GRAPH_GUARD
#define GRAPH_GUARD 1
#include <...system stuff...>
namespace Graph_lib {
// lots of other classes in here
// this is just one
struct Image : Shape {
Image(Point xy, string file_name, Suffix::Encoding e = Suffix::none);
//rest of class
}
}
What could be going wrong here?
Edit: this is the command I'm using to compile:
g++-4.6 -std=c++0x *.cpp -lfltk -lfltk_images
It appears as though you have forgotten to link your project with Graph.cpp, or whatever file(s) hold the implementations of the Graph_lib class methods.
Looks like your Graph library is missing.
When linking using g++, use -l <Graph lib>
I am a leda-6.3 library user.
I used graphwin to manipulate and display graphs, but I found that references
to graphwin methods are undefined while compiling the code although they
are declared in the LEDA/incl/LEDA/graphics/graphwin.h
So I think it is a problem of object file.
#include <LEDA/graphics/graphwin.h>
#include <LEDA/graph/graph_alg.h>
using namespace leda;
int main()
{
GraphWin gw("LEDA Graph Editor");
node u=gw.new_node(point(100,100));
node v=gw.new_node(point(100,200));
gw.new_edge(u,v);
gw.display();
gw.get_window().read_mouse();
graph& G=gw.get_graph();
G.new_node();
gw.get_window().read_mouse();
gw.update_graph();
gw.get_window().read_mouse();
return 0;
}
compilation: g++ -I$LEDAROOT/incl -L$LEDAROOT gw.cpp -lleda -lX11 -lm -o gw
ERROR :
/tmp/ccVHyRbL.o: In function `main':
gw.cpp:(.text+0x1e): undefined reference to `leda::GraphWin::GraphWin(char const*)'
gw.cpp:(.text+0x58): undefined reference to `leda::GraphWin::new_node(leda::point const&)'
gw.cpp:(.text+0xc6): undefined reference to `leda::GraphWin::new_node(leda::point const&)'
gw.cpp:(.text+0x11c): undefined reference to `leda::GraphWin::new_edge(leda::node_struct*, leda::node_struct*)'
gw.cpp:(.text+0x128): undefined reference to `leda::GraphWin::display()'
gw.cpp:(.text+0x17e): undefined reference to `leda::GraphWin::update_graph()'
collect2: ld returned 1 exit status
Which edition of LEDA are you using?
Please consider that free edition of LEDA does not contain GraphWin.
So, it dos not contain GraphWin libraries, which results to getting such errors while compiling your program.