# \`undefined reference\` and \`bad reloc address\` errors while using BinaryBuilder

**URL:** <https://discourse.julialang.org/t/undefined-reference-and-bad-reloc-address-errors-while-using-binarybuilder/74828>\
**Category:** General Usage\
**Tags:** binarybuilder\
**Created:** [January 18, 2022, 7:48pm UTC](https://discourse.julialang.org/t/undefined-reference-and-bad-reloc-address-errors-while-using-binarybuilder/74828 "2022-01-18T19:48:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielmatz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielmatz/32/2285_2.png) [@danielmatz](https://discourse.julialang.org/u/danielmatz)\
**Post date:** [January 18, 2022, 7:48pm UTC](https://discourse.julialang.org/t/undefined-reference-and-bad-reloc-address-errors-while-using-binarybuilder/74828/1 "2022-01-18T19:48:14Z")

</div>

I’m trying to use BinaryBuilder for a private package, but I am getting some errors that I don’t understand. I can’t share the code, but I’m hoping that something in the error message or in my `build_tarballs.jl` or `makefile` (included below) will spark an idea from someone.

> **Error messages**
>
> ```julia
> .build/common/source/Ephemeris.o:Ephemeris.cpp:(.text+0x141d): undefined reference to `bodn2c_c'
> .build/common/source/Ephemeris.o:Ephemeris.cpp:(.text+0x1433): undefined reference to `failed_c'
> .build/common/source/Ephemeris.o:Ephemeris.cpp:(.text+0x161e): undefined reference to `ltime_c'
> .build/common/source/Ephemeris.o:Ephemeris.cpp:(.text+0x1623): undefined reference to `failed_c'
> .build/common/source/Ephemeris.o:Ephemeris.cpp:(.text+0x1818): undefined reference to `subslr_c'
> .build/common/source/Ephemeris.o:Ephemeris.cpp:(.text+0x1842): undefined reference to `reclat_c'
> .build/common/source/Ephemeris.o:Ephemeris.cpp:(.text+0x1847): undefined reference to `failed_c'
> .build/common/source/Ephemeris.o:Ephemeris.cpp:(.text+0x1a68): undefined reference to `spkpos_c'
> .build/common/source/Ephemeris.o:Ephemeris.cpp:(.text+0x1a92): undefined reference to `recrad_c'
> .build/common/source/Ephemeris.o:Ephemeris.cpp:(.text+0x1af5): undefined reference to `failed_c'
> .build/common/source/Ephemeris.o:Ephemeris.cpp:(.text+0x1c3e): undefined reference to `lspcn_c'
> .build/common/source/Ephemeris.o:Ephemeris.cpp:(.text+0x1c50): undefined reference to `failed_c'
> .build/common/source/Ephemeris.o:Ephemeris.cpp:(.text+0x1f4a): undefined reference to `spkgeo_c'
> .build/common/source/Ephemeris.o:Ephemeris.cpp:(.text+0x1f4f): undefined reference to `failed_c'
> .build/common/source/Ephemeris.o:Ephemeris.cpp:(.text+0x2190): undefined reference to `latsrf_c'
> .build/common/source/Ephemeris.o:Ephemeris.cpp:(.text+0x22d3): undefined reference to `ilumin_c'
> .build/common/source/Ephemeris.o:Ephemeris.cpp:(.text+0x22d8): undefined reference to `failed_c'
> /opt/x86_64-w64-mingw32/bin/../lib/gcc/x86_64-w64-mingw32/4.8.5/../../../../x86_64-w64-mingw32/bin/ld: .build/common/source/Ephemeris.o: bad reloc address 0x0 in section `.data'
> collect2: error: ld returned 1 exit status
> make: *** [makefile:12: .build/libgram.dll] Error 1
> Previous command exited with 2
> 
> ```

> **build\_tarballs.jl**
>
> ```julia
> using BinaryBuilder
> 
> name = "GRAM"
> version = v"1.4.0"
> sources = [
> DirectorySource("GRAM"),
> ]
> 
> script = raw"""
> cd ${WORKSPACE}/srcdir
> make
> 
> cp .build/libgram.${dlext} ${prefix}/lib/
> """
> 
> platforms = supported_platforms(
> exclude = function(platform)
> startswith(triplet(platform), "armv6l-linux") ||
> startswith(triplet(platform), "aarch64-apple-darwin")
> end,
> )
> platforms = expand_cxxstring_abis(platforms)
> 
> products = [
> LibraryProduct("libgram", :libgram),
> ]
> 
> dependencies = [
> Dependency("CSPICE_jll"),
> ]
> 
> build_tarballs(ARGS, name, version, sources, script, platforms, products, dependencies; julia_compat = "1.6")
> 
> ```

> **makefile**
>
> ```julia
> SUBDIRECTORIES := common Earth Jupiter Mars Neptune Titan Uranus Venus
> SOURCE_FILES := $(foreach dir,$(SUBDIRECTORIES),$(wildcard $(dir)/source/*.cpp))
> INCLUDE_DIRECTORIES := $(foreach dir,$(SUBDIRECTORIES),$(dir)/include)
> OBJECT_FILES := $(addprefix .build/,$(patsubst %.cpp,%.o,$(SOURCE_FILES)))
> 
> .PHONY: all
> all: .build/libgram.$(dlext)
> 
> .build/libgram.$(dlext): $(OBJECT_FILES)
> $(CXX) $(LDFLAGS) $(LIBS) -shared -fPIC -L$(prefix)/lib -lcspice -o $@ $^
> 
> .build/%.o: %.cpp
> mkdir -p $(@D)
> $(CXX) $(CXXFLAGS) $(foreach dir,$(INCLUDE_DIRECTORIES),-I$(dir)) -I${prefix}/include -std=c++11 -fPIC -Wall -c -o $@ $<
> 
> .PHONY: clean
> clean:
> $(RM) -r .build
> 
> ```

The undefined reference errors are all related to the `CSPICE` library, which is in Yggdrasil.

My setup works for many platforms, but yields the above errors for a few. Most recently it failed for `x86_64-w64-mingw32` and `i686-w64-mingw32`. It may only be Windows platforms where it fails, but I’m not certain, yet.

Does anyone have any ideas for me on how to proceed?

---

<div class="post-metadata">

**Author:** ![contradict](https://avatars.discourse-cdn.com/v4/letter/c/ac91a4/32.png) [@contradict](https://discourse.julialang.org/u/contradict)\
**Post date:** [January 18, 2022, 7:57pm UTC](https://discourse.julialang.org/t/undefined-reference-and-bad-reloc-address-errors-while-using-binarybuilder/74828/2 "2022-01-18T19:57:11Z")

</div>

I think this is a link order problem. Try moving `-lcspice` to the end of the link command:

```
$(CXX) $(LDFLAGS) $(LIBS) -shared -fPIC -L$(prefix)/lib -o $@ $^ -lcspice

```

---

<div class="post-metadata">

**Author:** ![danielmatz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielmatz/32/2285_2.png) [@danielmatz](https://discourse.julialang.org/u/danielmatz)\
**Post date:** [January 18, 2022, 9:35pm UTC](https://discourse.julialang.org/t/undefined-reference-and-bad-reloc-address-errors-while-using-binarybuilder/74828/3 "2022-01-18T21:35:57Z")

</div>

Good catch! Thank you! I knew that within 15 minutes of posting this, one of the many smart people here would spot my error…

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [January 18, 2022, 9:45pm UTC](https://discourse.julialang.org/t/undefined-reference-and-bad-reloc-address-errors-while-using-binarybuilder/74828/4 "2022-01-18T21:45:18Z")

</div>

Side note, when having this kind of problems it’d be helpful to always show the compiler invocation, not just the error message.
