Using GtkD on Linux, how do i statically link the compiled library? - static-libraries

This is kind of linked to this question here: GtkD (the Gtk+bindings for the D language) why compile it?
I'm using GtkD with the D programming language on Ubuntu 12.04 and i'm stuck trying to statically link the compiled libs with my program. Once GtkD is compiled there are three libraries
libgtkd.a
libgtkdgl.a
libgtkdsv.a
After doing make install these are placed into the /usr/local/lib/ folder and the GtkD source is placed inside the /usr/local/includes/d/ folder. I've also compiled the source to *.di files and placed them in the relevant folders in /usr/local/includes/d/ as the make script doesn't do this by default.
Here's the source i want to compile.
pragma(lib, "/usr/local/lib/libgtkd.a");
import gtk.MainWindow;
import gtk.Label;
import gtk.Main;
void main(string[] args)
{
Main.init(args);
MainWindow win = new MainWindow("Hello World!");
win.setDefaultSize(200, 100);
win.add(new Label("Hello World"));
win.showAll();
Main.run();
}
Here's the compiler command i use:
rdmd -L-ldl hello_world.d
Here's the errors:
/usr/local/lib/libgtkd.a(Loader.o): In function `_D4gtkc6Loader12pLoadLibraryFAyaE4gtkc6Loader4RTLDZPv':
src/gtkc/Loader.d:(.text._D4gtkc6Loader12pLoadLibraryFAyaE4gtkc6Loader4RTLDZPv+0x28): undefined reference to `dlopen'
src/gtkc/Loader.d:(.text._D4gtkc6Loader12pLoadLibraryFAyaE4gtkc6Loader4RTLDZPv+0x31): undefined reference to `dlerror'
/usr/local/lib/libgtkd.a(Loader.o): In function `_D4gtkc6Loader10pGetSymbolFPvAyaZPv':
src/gtkc/Loader.d:(.text._D4gtkc6Loader10pGetSymbolFPvAyaZPv+0x23): undefined reference to `dlsym'
src/gtkc/Loader.d:(.text._D4gtkc6Loader10pGetSymbolFPvAyaZPv+0x2c): undefined reference to `dlerror'
/usr/local/lib/libgtkd.a(Loader.o): In function `_D4gtkc6Loader14pUnloadLibraryFPvZi':
src/gtkc/Loader.d:(.text._D4gtkc6Loader14pUnloadLibraryFPvZi+0x9): undefined reference to `dlclose'
collect2: ld returned 1 exit status
--- errorlevel 1
shell returned 1
Any ideas what i'm doing wrong? It looks like an ld error but that's linked right?

The order of arguments matters with ld, the linker. In general you should place dependencies after the code/library which depends on them. So I'd rewrite your pragmas like so:
pragma(lib, "gtkd"); // let ld find it in your path
pragma(lib, "dl"); // gtkd depends on dl, so link it after
Now try compiling with:
dmd hello_world.d

you pass it along in the arguments dmd knows that they need to be passed to the linker
rdmd libgtkd.a libgtkdgl.a libgtkdsv.a -L-ldl hello_world.d

Related

BOOST programm options error when importing in python

I have a boost module called arachne, when importing this module in a python script called submitArachne I get the follwoing error: Kolophon/shlib/arachne/arachne.so: undefined symbol: _ZNK5boost15program_options22error_with_option_name4whatEv
I was not able to find any documentation from boost regarding this error. Since this is a undefined symbol error, I feel like this is a compiler problem / linker problem. I set the linker flags as follows:
BOOSTLIBS = -L$(BOOSTLIB_DIR)
BOOSTLIBS += -lboost_python39 -lboost_program_options -lboost_filesystem -lboost_system
MYLIBS += $(PYTHONLIBS) $(BOOSTLIBS)
I am currently using gcc/8.3.0 and Boost/1.78.0. The python version is Python/3.9.12.
I was not able to find any possible solutions/documentation regarding this error. I hope that someone has an idea what could be going wrong here.
I already played a little bit with the linker flags but I was not able to find a solution to this unique problem.

Rust: x86_64-w64-mingw32/bin/ld.exe: cannot find -lglfw3

I'm trying to use GLFW with rust on windows and I'm getting this error upon running the program:
error: linking with `x86_64-w64-mingw32-gcc` failed: exit code: 1
|
= note: "x86_64-w64-mingw32-gcc" "-fno-use-linker-plugin" "-Wl,--dynamicbase" "-Wl,--disable-auto-image-base" "-m64" "-Wl,--high-entropy-va" (then a ton of other stuff that leaks my files)
= note: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lglfw3
collect2.exe: error: ld returned 1 exit status
All I am doing in the program is importing the package.
I have been trying to solve this for a while, and it doesn't help that I'm very new to rust. I guess this is what I get with trying to use rust on windows.
Thanks for your help!
Add a -L<path> linker flag where <path> points to the folder containing libglfw3.a (or libglfw3.dll.a in case of shared library).

Can't compile and link library

I try to use a library compiled with gcc called matlisp based on fortran code. After specifyng the f77 compiler, I could performed the autoreconf, configure and make command to obtain the file libmatlisp.so.
But when I try to use it i get a:
Error opening shared object ".../libmatlisp.so":
/usr/lib/libf2c.so.2: undefined symbol: MAIN__.
And when i perform the command ld libmatlisp.so i get:
...
libmatlisp.so: undefined reference to `idamax_'
libmatlisp.so: undefined reference to `dger_'
/usr/lib/libf2c.so.2: undefined reference to `MAIN__'
libmatlisp.so: undefined reference to `zscal_'
libmatlisp.so: undefined reference to `dscal_'
....
Is there a way to improve the situation?
I already try this solution but it does not work.
I also try to change the compiler to gfortran but i get some some run time error messages mentionning missing libraries that are part of libf2c.
Ok. I move to a more recent source of matlisp 2012 instead of 2003, and it run properly in my environment now.

Can't find libstdc++?

I built gcc 4.9.0 from source, and was also planning on building clang 3.4.2, however something seems to have gone awry with regards to libstdc++, as the clang build baled pretty quickly with the linker complaining about various undefined references from std.
Indeed, I then tried compiling and linking the trivial program:
#include <iostream>
int main() {
std::cout << 42;
}
and again hit linker errors:
/tmp/ccrptgVW.o:temp.cpp:function main: error: undefined reference to 'std::cout'
/tmp/ccrptgVW.o:temp.cpp:function main: error: undefined reference to 'std::ostream::operator<<(int)'
/tmp/ccrptgVW.o:temp.cpp:function __static_initialization_and_destruction_0(int, int): error: undefined reference to 'std::ios_base::Init::Init()'
/tmp/ccrptgVW.o:temp.cpp:function __static_initialization_and_destruction_0(int, int): error: undefined reference to 'std::ios_base::Init::~Init()'
collect2: error: ld returned 1 exit status
(full gcc -v output), both with my freshly-minted gcc 4.9.0 and my Ubuntu's stock gcc 4.6.3.
libstdc++.so exists, in /usr/local/lib64:
ls /usr/local/lib64/libstd*
/usr/local/lib64/libstdc++.a
/usr/local/lib64/libstdc++.so
/usr/local/lib64/libstdc++.so.6.0.20
/usr/local/lib64/libstdc++.la
/usr/local/lib64/libstdc++.so.6
/usr/local/lib64/libstdc++.so.6.0.20-gdb.py
and this directory appears in LIBRARY_PATH and as an -L argument to collect2 in the verbose gcc output.
How do I restore sanity to my system and have the linker find the shared library?
As turns out from your comment, you compiled with gcc rather than g++.
Do not take it as an error, as the compilation went fine! What's showing up is a linker error. Indeed, gcc will tell ld to link against the C standard library rather than the C++ standard one.
To solve, either go for g++ directly or pass -lstdc++.

cython: memoryview build error with mingw

I have been writing some python extension modules with cython. The extensions I've written build and work well. Then, I wanted to use typed memoryviews, when accessing my numpy arrays, as they seem to have several advantages http://docs.cython.org/src/userguide/memoryviews.html
However, as soon as I use a memoryview in my cython code I will get an error when building the extension. For example, if I add this test line:
cdef double[:, ::1] X = np.zeros((100, 100))
to an existing, working cython extension. I will get the following errors:
C:\MinGW\bin\gcc.exe -shared -s build\temp.win32-2.7\Release\image_box.o build\temp.win32-2.7\Release\image_box.def -Lc:\python27\libs -Lc:\python27\PCbuild -lp
ython27 -lmsvcr90 -o x:\ARframework\python\image_ops\image_box.pyd
build\temp.win32-2.7\Release\image_box.o:image_box.c:(.text+0xe23): undefined reference to `___sync_fetch_and_add_4'
build\temp.win32-2.7\Release\image_box.o:image_box.c:(.text+0x3318): undefined reference to `___sync_fetch_and_add_4'
build\temp.win32-2.7\Release\image_box.o:image_box.c:(.text+0x4c81): undefined reference to `___sync_fetch_and_sub_4'
build\temp.win32-2.7\Release\image_box.o:image_box.c:(.text+0x4d37): undefined reference to `___sync_fetch_and_sub_4'
build\temp.win32-2.7\Release\image_box.o:image_box.c:(.text+0x10767): undefined reference to `___sync_fetch_and_sub_4'
build\temp.win32-2.7\Release\image_box.o:image_box.c:(.text+0x10793): undefined reference to `___sync_fetch_and_sub_4'
collect2.exe: error: ld returned 1 exit status
error: command 'gcc' failed with exit status 1
I've tried to add -march=i486 to the gcc line, as suggested in this post:
undefined reference to sync_fetch_and_add_4
but that didn't solve the problem. For that matter, I also tried -march=i586 and -march=pentium without success.
Any idea what's going on here?
My platform is Windows 7, mingw version is 4.70, Cython version is 0.17.1
Thanks
I found a solution.
Actually, the gcc flag -march=i486 does solve the problem! However, when I tested it in the console I just applied it to the gcc line for the link step (that's where I got the errors) and as it didn't solve the problem I thought it just didn't work.
In fact, I need to use -march=i486 both in the compile and link steps, then there is no errors anymore.
As to how to include these flags when I build the extension, I have tried to add
import os
os.environ['LDFLAGS'] = '-march=i486'
os.environ['CFLAGS'] = '-march=i486'
to the setup.py but it didn't seem to work.
So I have modified the c:\python27\Lib\distutils\cygwinccompiler.py to include these flags in the compile and link steps. Not sure if this is very elegant way of setting these flags. Any alternatives are welcome!

Resources