undefined reference to opEquals: Linker errors with Derelict3 Bindings to SDL2 - sdl

I am trying to write a simple hello world using the Derelict3 bindings for SDL2. I am getting errors during linking that I have not seen before.
module main;
import derelict.sdl2.sdl;
pragma(lib, "DerelictSDL2");
pragma(lib, "DerelictUtil");
pragma(lib, "dl");
int main(string[] args)
{
DerelictSDL2.load();
return 0;
}
command line:
dmd src/main.d -debug -Iinclude -Isrc
-L-Llib -L-lSDL2
output:
> lib/libDerelictSDL2.a(sdl_55_698.o):(.rodata+0x41e8): undefined reference to `_D6object6Object8opEqualsMFC6ObjectC6ObjectZb'
> lib/libDerelictUtil.a(exception_9b_6db.o):(.rodata+0xe8): undefined
> reference to `_D6object6Object8opEqualsMFC6ObjectC6ObjectZb'
> lib/libDerelictUtil.a(exception_9d_89d.o):(.rodata+0x178): undefined
> reference to `_D6object6Object8opEqualsMFC6ObjectC6ObjectZb'
> lib/libDerelictUtil.a(exception_9e_7a5.o):(.rodata+0x118): undefined
> reference to `_D6object6Object8opEqualsMFC6ObjectC6ObjectZb' collect2:
> ld returned 1 exit status
> --- errorlevel 1
what I have tried:
verify that Derelict3 and SDL2 are up-to-date
changing the order of my linked libraries
searching online: I could only find 1 other post related to this: http://dblog.aldacron.net/forum/index.php?topic=834.0
I am using DMD64 D Compiler v2.063.2.
Any help is appreciated.
Thanks.

It looks like Derelict was built using a different version of D than the one you're using to build your program. Try rebuilding Derelict from source.

Related

CImg library when compiling return undefined reference to `__imp_SetDIBitsToDevice'

I'm using VSCode on Windows 10 with MinGW compiler installed. I've tried using CImg library to edit images (http://cimg.eu/), and when I'm trying to compile code from tutorial (http://cimg.eu/reference/group__cimg__tutorial.html) I get this error:
C:\Users\Martini\AppData\Local\Temp\ccBswQ5w.o:tutorial.cpp:(.text$_ZN12cimg_library11CImgDisplay5paintEv[_ZN12cimg_library11CImgDisplay5paintEv]+0xba): undefined reference to `__imp_SetDIBitsToDevice'
collect2.exe: error: ld returned 1 exit status
I have CImg.h file located in folder with tutorial.cpp. Here's command I'm using to compile:
g++ tutorial.cpp -o tutorial.exe
It's my first time working with libraries in C++, and CImg looks fairly easy to use, but if you have used other libraries to edit photos, let me know.
Thanks in advance!
You need to link to GDI32 on Windows I think. Something like:
g++ tutorial.cpp -lgdi32 -o tutorial.exe

g++ building c++ program with boost dependencies

I want to compile and run a simple c++ websocket application with g++ on windows.
Boost was installed like this:
./bootstrap.bat mingw
./b2.exe install --prefix=C:/boostLibs toolset=gcc
My c++ includes look like this:
#include <websocketpp/config/asio_no_tls.hpp>
#include <websocketpp/server.hpp>
#include <iostream>
This websocket sample was provided by https://github.com/zaphoyd/websocketpp
In order to build the project I issue this command:
g++ -Wno-deprecated -I ./cppServer/libs/ -I C:\boostLibs\include\boost-1_55 -L C:\boostLibs\lib -g ./cppServer/server.cpp -lboost_system
Which leeds me to this error message:
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lboost_system
collect2.exe: error: ld returned 1 exit status
If I try to build without -lboost_system, I get a very long exception, starting with:
C:/boostLibs/include/boost-1_55/boost/system/error_code.hpp:222: undefined reference to boost::system::generic_category()'
C:/boostLibs/include/boost-1_55/boost/system/error_code.hpp:223: undefined reference toboost::system::generic_category()'
C:/boostLibs/include/boost-1_55/boost/system/error_code.hpp:224: undefined reference to boost::system::system_category()'
C:\Users\JOHANN~1.HAS\AppData\Local\Temp\ccpKMWTH.o: In functionZN5boost6system10error_codeC1Ev':
C:/boostLibs/include/boost-1_55/boost/system/error_code.hpp:323: undefined reference to boost::system::system_category()'
C:\Users\JOHANN~1.HAS\AppData\Local\Temp\ccpKMWTH.o: In functionZN5boost6system4errc20make_error_conditionENS1_6errc_tE':
C:/boostLibs/include/boost-1_55/boost/system/error_code.hpp:488: undefined reference to boost::system::generic_category()'
C:\Users\JOHANN~1.HAS\AppData\Local\Temp\ccpKMWTH.o: In functionZN5boost16thread_exceptionC2EiPKc'
So what am I missing? I can't figure it out right now.
Link to boost_system as -lboost_system-mgw63-mt-1_55, because this is what those files are called. See boost library naming for more details.
When you build boost you may like to specify --layout=system to b2.exe so that your files do not have that -mgw63-mt-1_55 in the filename and then just use -lboost_system when linking against it.

TCL - undefined reference to `_imp__Tcl_ResetResult' for g++

I am relatively new to TCL and I am trying to execute a C++ program using SWIG on Windows 10. Using command prompt. I am not using Visual Studio
I am basically trying to run r_cpp using C++ MinGW from TCL
C:\swigwin-3.0.12\Examples\r\class>swig -c++ -tcl example.i`
C:\swigwin-3.0.12\Examples\r\class>g++ -c example.cxx
C:\swigwin-3.0.12\Examples\r\class>g++ -c example_wrap.cxx -I/Tcl/include/tcl8.6
C:\swigwin-3.0.12\Examples\r\class>g++ -shared example.o example_wrap.o -o example.dll
example_wrap.o:example_wrap.cxx:(.text+0x981): undefined reference to `_imp__Tcl_ResetResult'`example_wrap.o:example_wrap.cxx:(.text+0x995): undefined reference to `_imp__Tcl_SetObjResult'`example_wrap.o:example_wrap.cxx:(.text+0x9b9): undefined reference to `_imp__Tcl_SetErrorCode'
example_wrap.o:example_wrap.cxx:(.text+0x9cf): undefined reference to `_imp__Tcl_ResetResult'
example_wrap.o:example_wrap.cxx:(.text+0x9f3): undefined reference to `_imp__Tcl_SetErrorCode
example_wrap.o:example_wrap.cxx:(.text+0xa1e): undefined reference to `_imp__Tcl_AppendResult'
example_wrap.o:example_wrap.cxx:(.text+0xa3c): undefined reference to `_imp__Tcl_NewStringObj'
collect2.exe: error: ld returned 1 exit status
Can someone please help me on this??
Should I make changes to my Makefile.in in the folder?????
Its been a while since I've done C but I would think that you are not linking in the static/shared library that has the functions that g++ is complaining about. In this case the tcl library something like libTclXX.dll. I'm not too familiar with command lines on windows but something like -llibtclXX.dll -L path_to_tcllib could be added. If I recall correctly tcl does provide a stub library for you to link staticially your extension then at runtime the shared library can be use to resolve the functions... so something like -llibtclstubs.dll . look in your installed lib directory for actual names of these libraries.

Linker error in g++ while trying to link to SDL_ttf shared object files

I am trying to use the SDL_ttf development library in an Ubuntu environment. I started by downloading the dev libraries via: sudo apt-get install libsdl-ttf2.0-dev.
Next, I imported the header file in my code as so:
#include <SDL_ttf.h>
When I compile with the command:
g++ -g -I /usr/include/SDL Main.cpp -lSDL -lSDL_image -lSDL_ttf land.cpp PerlinNoise.cpp Util.cpp org.cpp Init.cpp `sdl-config --libs
I get the following output:
/tmp/ccpLKljA.o: In function `init()':
/home/zoo/Desktop/World-A/Util.cpp:39: undefined reference to `TTF_Init'
/home/zoo/Desktop/World-A/Util.cpp:42: undefined reference to `TTF_Quit'
/home/zoo/Desktop/World-A/Util.cpp:48: undefined reference to `TTF_OpenFont'
/home/zoo/Desktop/World-A/Util.cpp:52: undefined reference to `TTF_Quit'
collect2: ld returned 1 exit status
I understand this is a linker error however I do not know what to do to fix it. I know that the -lSDL_ttf command is not doing anything because removing it does not change anything. I tried to reference the .so file however that didn't change the results. I did this reference via the command: -LlibSDL_ttf-2.0.so.0.6.3. I am able to view the .so file and it does contain the commands listed above.
You have to put land.cpp, and the rest of the CPP files, before the libraries on the command line.

Hello world with boost python and python 3.2

So I'm trying to interface python 3.2 and c++ using boost python, and have come across many many issues. I've finally gotten it to compile using the 2.7 libraries and it works, but I can't seem to make it work with python 3.2.
Here's the c++ code
#include <iostream>
using namespace std;
void say_hello(const char* name) {
cout << "Hello " << name << "!\n";
}
int main(){return 0;}
#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
using namespace boost::python;
BOOST_PYTHON_MODULE(hello)
{
def("say_hello", say_hello);
}
If I compile it using the 2.7 libraries it works just fine, but when I use the 3.2 libraries I get tons of undefined references from libboost_python.so
Otherwise I wrote a little bit of python to make it work:
from distutils.core import setup
from distutils.extension import Extension
setup(name="PackageName",
ext_modules=[
Extension("hello", ["testBoost.cpp"],
libraries = ["boost_python"])
])
and this will create an so using python 3.2 or 2.7 build, but when I open the python 3 interpreter and attempt to import the so it give me the error undefined symbol PyClass_Type from libboost_python.so again. Any ideas? Is boost python compatible with python 3.x?
If the information is useful, here is my attempted compile using 3.2:
$ g++ testBoost.cpp -I/usr/include/python3.2 -I/usr/local/include/boost/python -lboost_python -lpython3.2mu
/tmp/ccdmU1Yu.o: In function `PyInit_hello':
testBoost.cpp:(.text+0xc2): undefined reference to `boost::python::detail::init_module(PyModuleDef&, void (*)())'
/usr/local/lib/libboost_python.so: undefined reference to `PyString_Size'
/usr/local/lib/libboost_python.so: undefined reference to `PyFile_FromString'
/usr/local/lib/libboost_python.so: undefined reference to `PyString_Type'
/usr/local/lib/libboost_python.so: undefined reference to `PyInt_Type'
/usr/local/lib/libboost_python.so: undefined reference to `PyString_FromString'
/usr/local/lib/libboost_python.so: undefined reference to `PyString_FromStringAndSize'
/usr/local/lib/libboost_python.so: undefined reference to `Py_InitModule4_64'
/usr/local/lib/libboost_python.so: undefined reference to `PyString_FromFormat'
/usr/local/lib/libboost_python.so: undefined reference to `PyNumber_Divide'
/usr/local/lib/libboost_python.so: undefined reference to `PyNumber_InPlaceDivide'
/usr/local/lib/libboost_python.so: undefined reference to `PyInt_AsLong'
/usr/local/lib/libboost_python.so: undefined reference to `PyString_InternFromString'
/usr/local/lib/libboost_python.so: undefined reference to `PyClass_Type'
/usr/local/lib/libboost_python.so: undefined reference to `PyString_AsString'
/usr/local/lib/libboost_python.so: undefined reference to `PyInt_FromLong'
/usr/local/lib/libboost_python.so: undefined reference to `PyFile_AsFile'
collect2: ld returned 1 exit status
And the error from the python 3 interpreter is
File "<stdin>", line 1, in <module>
ImportError: /usr/local/lib/libboost_python.so.1.47.0: undefined symbol: PyClass_Type
Thanks for any help!
I had the exact same problem, with Ubuntu 12.04. I installed the 1.48 version of the library and had to link with libboost_python-py32.so instead of libboost_python.so After this the linker errors was gone.
The above c++ code compiles into a module with
$ g++ testBoost.cpp -I/usr/include/python3.2 -I/usr/local/include/boost/python -lboost_python3 -lpython3.2mu -o hello.so -shared
This compile command adds -lboost_python3, and -shared, and also the naming convention for python extension modules. You should also install the python3-dev package, and configure/build/install boost with python3, if you haven't already.
In python 3, I can then do the following:
$ python3
Python 3.2 (r32:88445, Mar 25 2011, 19:28:28)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import hello
>>> hello.say_hello('bill')
Hello bill!
>>>
You should be off to the races at that point.
Although this discussion old, just for the record:
Modify project-config.jam to change the python version to your setup
# Python configuration
using python : 3.4 : /usr ;
Then build boost:
./b2 clean
./b2 --with-python link=static cxxflags="-std=c++11 -fPIC" variant=release stage
./b2 --with-python link=static cxxflags="-std=c++11 -fPIC" variant=release install
The later command requires super user privileges. Then move to the folder containing C++ code for the extension:
g++ -std=c++11 hellopy.cpp -I/usr/include/python3.4 -I/usr/local/include/boost/python -lboost_python3 -o hello.so -shared -fPIC
You can then import hello into your python environment.
Linking in the python libraries (for e.g. -L/usr/lib/x86_64-linux-gnu -lpython2.7 on linux or find_package(PythonLibs) in CMake1) will make this linker issue go away.
Here is a more detailed explanation of the issue below. On the command line,
$ nm --dynamic <path-to>/libboost_python.so | grep PyString_Size
If you are feeling lazy and assuming your libboost_python is linking to python2.7, just run this
$ nm --dynamic `locate libboost_python27.so | awk 'NR==1'` | grep PyString_Size
You should see something like
U PyString_Size
So PyString_Size is undefined (U) in libboost_python27.so. This is what the linker was complaining about. We've confirmed that. Now let's look for this symbol in libpython.
$ nm --dynamic `locate libpython2.7.so | awk 'NR==1'` | grep PyString_Size
On my machine, I saw something like this:
00000000000f0530 T PyString_Size
The T indicates that the text for this symbol is at the address indicated. So this is proof that we were not linking in libpython in addition to libboost_python.
1 Why aren't you using CMake? :)