Welcome to Part Two of my try-to-use-Nix-for-development!
In this session, I am trying to do something that I think is meant to be simple: package a static library and use it to compile C++ software (including within a nix-shell
)
(And again, if it matters, I am on Nix-Darwin.)
My understanding is that, if I run nix-shell -p MyLibrary
, I should then see something like this:
$ ld -v
@(#)PROGRAM:ld PROJECT:ld64-274.2
configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em (tvOS)
Library search paths:
/nix/store/2lykcxvy85rh4wk48wj77bjcia6asv7f-libc++-7.1.0/lib
/nix/store/0wvwlf3pbkgh8k5g52q666b3w3s3bm0m-libc++abi-7.1.0/lib
/nix/store/cf9dnf1ibm5p958kfyy60b7kz2vf5ry4-compiler-rt-7.1.0/lib
/nix/store/dnzqnwr0xl4zdfqrqgbdk0nbflfq4m5r-lldb-7.1.0/lib
...
/nix/store/yvlj3chlvn6074ajd0c43c0khpwijydy-MyLibrary-0.0.1/lib
...
For example, with the (totally randomly chosen) jack2
package:
$ nix-shell -p jack2 --run 'ld -v'
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
@(#)PROGRAM:ld PROJECT:ld64-274.2
configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em (tvOS)
Library search paths:
/nix/store/2lykcxvy85rh4wk48wj77bjcia6asv7f-libc++-7.1.0/lib
/nix/store/0wvwlf3pbkgh8k5g52q666b3w3s3bm0m-libc++abi-7.1.0/lib
/nix/store/cf9dnf1ibm5p958kfyy60b7kz2vf5ry4-compiler-rt-7.1.0/lib
/nix/store/6rlip0i5ss8naw6l30ly0rasyfmq5pss-jack2-1.9.12/lib
/nix/store/2lykcxvy85rh4wk48wj77bjcia6asv7f-libc++-7.1.0/lib
/nix/store/0wvwlf3pbkgh8k5g52q666b3w3s3bm0m-libc++abi-7.1.0/lib
/nix/store/cf9dnf1ibm5p958kfyy60b7kz2vf5ry4-compiler-rt-7.1.0/lib
/nix/store/6rlip0i5ss8naw6l30ly0rasyfmq5pss-jack2-1.9.12/lib
/nix/store/v6y7h7hs82n9zm841l2p8f2pm3vsa1y2-Libsystem-osx-10.12.6/lib
Framework search paths:
ld: no object files specified
We can see that the jack2
lib dir has been added. I think this is connected with the fact that NIX_LDFLAGS
has been updated to include it, like this:
$ nix-shell -p jack2 --run 'echo $NIX_LDFLAGS | tr " " "\n"'
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
-L/nix/store/2lykcxvy85rh4wk48wj77bjcia6asv7f-libc++-7.1.0/lib
-L/nix/store/0wvwlf3pbkgh8k5g52q666b3w3s3bm0m-libc++abi-7.1.0/lib
-L/nix/store/cf9dnf1ibm5p958kfyy60b7kz2vf5ry4-compiler-rt-7.1.0/lib
-L/nix/store/6rlip0i5ss8naw6l30ly0rasyfmq5pss-jack2-1.9.12/lib
-L/nix/store/2lykcxvy85rh4wk48wj77bjcia6asv7f-libc++-7.1.0/lib
-L/nix/store/0wvwlf3pbkgh8k5g52q666b3w3s3bm0m-libc++abi-7.1.0/lib
-L/nix/store/cf9dnf1ibm5p958kfyy60b7kz2vf5ry4-compiler-rt-7.1.0/lib
-L/nix/store/6rlip0i5ss8naw6l30ly0rasyfmq5pss-jack2-1.9.12/lib
However, I am not seeing this with my library. I am emitting a .pc
and do see that pkg-config is working right (for both --libs
and --cflags
), like this:
$ nix-shell -p MyLibrary -p pkgconfig --run 'pkg-config --libs mylibrary'
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
-L/nix/store/572pzw116mjz5vc7mmbni3al7ld8kxbk-mylibrary-0.1/lib -lmy
and my library package directory structure is approximately:
/nix/store/572pzw116mjz5vc7mmbni3al7ld8kxbk-mylibrary-0.1
/nix/store/572pzw116mjz5vc7mmbni3al7ld8kxbk-mylibrary-0.1/lib/libmy.a
/nix/store/572pzw116mjz5vc7mmbni3al7ld8kxbk-mylibrary-0.1/lib/pkgconfig/mylibrary.pc
/nix/store/572pzw116mjz5vc7mmbni3al7ld8kxbk-mylibrary-0.1/include/mylibrary.h
So, I think my question is, is there something I am supposed to do in order to get my library into the NIX_LDFLAGS
?
Sorry if this is a dumb question