RejectedSoftware Forums

Sign up

Error building library project

Hello, I've started to use dub and until now its been great, thank you for providing us this pece of amazing software.

Have this error when trying to build a project with one file only. This file is supposed to be buildt has a shared library.
package.json file configuration is not a big deal, I just specify additionally "targetType": "dynamicLibrary" and "targetPath": "./lib/".

Projects will fail to build in the linking fase complaining about main:

...
dmd -m64 -c -of/.../lib/temp.o -debug -release -g -inline -O -wi -version=Havelib -I/.../lib/src src/lib.d
Linking...
dmd -of/.../lib/lib.so /.../lib/temp.o -m64 -g
/usr/lib64/libphobos2.a(dmain2
44d1a5.o): In function `main':
(.text.main+0xa): undefined reference to `
Dmain'
collect2: error: ld returned 1 exit status
--- errorlevel 1
Error: no main function specified
Error: Link command failed with exit code 1
...

Not sure if this is a bug or I'm just missing some option. Searched for a field that would allow me to add a parameter to dmd when he is linking, but not sure if this is available, not been able to found it. a "-c", would allow the project to compile.

Purpose is, I want to build this as a separated project/library, so that later I can have new projects using the library without having to build it or the source be included.

Not sure if I'm missing something, thats usualy the case, been using dub for a couple of days now.

Thank you...

Re: Error building library project

I think it was missing the -shared flag - fixed now, but I didn't test it yet.

Library targets and building in general are still quite simplistic and will get some big improvements at some point (like incremental builds, caching of build results, proper library target support etc.). But the time frame for this is currently completely unclear, unfortunately.

Re: Error building library project

I've tested to build my project a few days ago with dub from git master, it's now working has expected, it builds a shared library.

I did notice some quirks, it's not possible to add a sufix to the generated file (or am I wrong?), I've used the "postBuildCommands" to mv the generated shared lib to a file name containing the version ( from libxxx.so to libxxx.so.1.1.1). the strange is that if you declare this project has a dependency on another project it will use there the postBuildCommands as if they were declared on the subsequent project as normal after the linker, failing of course.
I've noticed the same behavior with the "lflags", they were also present on the subsequent project link command. So at the moment I can build a project has a sharedLib but not declare in other projects as a dependency.

Not sure if it's already there, but maybe can you consider for sharedLibs to add a field that would allow to add an additional suffix to the generated file? Currently Dub adds only ".so", but shared libs usually contain in the name also the version.

Another request/wish I would like to make is that if it's possible since we declared one project as a dependency to get also in this project a "$PACKAGE_DIR" similar variable, from the required project?
This would be great because it would allow to specify on the dependant project for the executable file, the rpath value and other settings from the library/required project, without having to have them hard coded in the ".json" file.

Maybe it's clear if I provide examples of the project files.

sharedLibrary project:

{ "name":"mysharedlib",
"targetType": "dynamicLibrary",
"libs":["phobos2"],
"targetPath":"./lib",
"lflags":["-soname=libmysharedlib.so.0"]}

Project (builds but includes code from the library):

{ "name":"proj",
"targetType": "executable",
"dependencies": { "mysharedlib": {"version":"~master"}}}

This will build and link but the binary will have my lib code included, not has a shared dependency.

How I'm creating it having a shared lib dependency:

{ "name":"proj",
"targetType": "executable",
"libs":["mysharedlib"],
"dflags": ["-I../mysharedlibfolder/include"],
"lflags":["-L../mysharedlibfolder/lib","-rpath=$PACKAGE_DIR/../mysharedlibfolder/lib"]

Has you can see I need to make a hard reference to the library project in all this *flags, it would be good to have a variable to allow this to be referenced independent of where the lib project stays.

$ ldd myexe
libmysharedlib.so.0 => /home/user/projfolder/../mysharedlibfolder/lib/libsru.so.0 (0x00007f98efc54000)
libphobos2.so.0.63 => /usr/lib/x86_64-linux-gnu/libphobos2.so.0.63 (0x00007f98eec0b000)

Thank you.