Skip to content

Conversation

WalterBright
Copy link
Member

Build phobos as .so as well as .a

@WalterBright
Copy link
Member Author

Needs dlang/druntime#470

@WalterBright
Copy link
Member Author

Remember to set export to something like this in order to use the shared library:

export LD_LIBRARY_PATH=/home/walter/cbx/mars/phobos/generated/linux/release/64:/home/walter/cbx/mars
/phobos/generated/linux/release/32

and build your app like this:

dmd foo -defaultlib=phobos2so

and it should link with the shared library. Linking with the static library is the default, and works as before.

@WalterBright
Copy link
Member Author

This is currently only for linux.

@ghost
Copy link

ghost commented Apr 4, 2013

Those instructions should be in the docs somewhere.

@WalterBright
Copy link
Member Author

Of course. But I don't want to spend time writing it all up unless we are sure this is the way we're going. Remember, nobody liked my last scheme :-)

@MartinNowak
Copy link
Member

Remember, nobody liked my last scheme :-)

Mine wasn't the right either.

dmd foo -defaultlib=phobos2so

Another way to do this is to install phobos2.so and phobos.a and use the following link flags

  • to optionally link against a shared library
    -defaultlib= -debuglib= -L-lphobos2 -L-lcurl -L-ldl -L-lpthread -L-lm -L-lrt
  • to mandatory link against a static library
    -defaultlib= -debuglib= -L-Bstatic -L-lphobos2 -L-Bdynamic -L-lcurl -L-ldl -L-lpthread -L-lm -L-lrt

BTW I hope we can get rid of the defaultlib and debuglib flags in the near future and handle this configuration issue with DFLAGS and dmd.conf.
This would also solve the link order bugs (Bugzilla 7044, Stackoverflow) we have with libcurl and which will happen again with libdl.

@MartinNowak
Copy link
Member

I'm fine with this pull request, so please merge when the autotester goes green.

@@ -151,6 +152,7 @@ DDOC=$(DMD)
# Set LIB, the ultimate target
ifeq (,$(findstring win,$(OS)))
LIB = $(ROOT)/libphobos2.a
LIBSO = $(ROOT)/libphobos2so.so
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an unusual convention. How about just leaving it to the extension? LIBSO = $(ROOT)/libphobos2.so

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that, it doesn't work to have both libphobos2.a and libphobos2.so. There's no linker switch to force picking one or the other.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is: bracket the -lphobos part with -Bstatic and -Bdynamic (those are linker flags. If you pass them to gcc you have to prepend -Wl,)

Example:
gcc -Wl,-Bstatic -lphobos -Wl,-Bdynamic
(-Bdynamic is default)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move forward with what we have in the interest of time. I'll pull.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My reading of -Bdynamic was it didn't have pervasive support.

andralex added a commit that referenced this pull request Apr 6, 2013
@andralex andralex merged commit 1890395 into dlang:master Apr 6, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants