Integration Event 21-03 Make errors

Hi, I am still trying to work through Integration Event 21-03. I am having trouble with the “Implement the Program” step 4, I am using a Mac. When I run “make” (i.e. the Docker approach), I get a libxml2 error. When I run make all (local approach) I get an ld error (ld: unknown option: --copy-dt-needed-entries). I posted the second error to StackOverflow here: https://stackoverflow.com/questions/66659451/c-clang-ld-unknown-option-copy-dt-needed-entries-error.

Appreciate any thoughts, guidance

If you run ld -v what do you get?

Thanks, was not sure what “-v for invocation” means. But, per the above just tried ld -v and not sure what the below means:

markstadtmueller@Tangram00186-MarkS location-reporter % ld -v
@(#)PROGRAM:ld  PROJECT:ld64-609.8
BUILD 15:07:46 Dec 18 2020
configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em
LTO support using: LLVM version 12.0.0, (clang-1200.0.32.29) (static support for 27, runtime is 27)
TAPI support using: Apple TAPI version 12.0.0 (tapi-1200.0.23.5)
markstadtmueller@Tangram00186-MarkS location-reporter %

So what I think is happening is that your ld is actually the FreeBSD ld, if it’s anything like my relatively clean but old personal mac. I also believe we need the GNU ld for our compilation in this case according to this link. So not sure if you should brew install llvm (which would install version 11 according to the brew formula), or install your latest XCode through the app store. But I would suspect either would get your make closer to working.
In the case you already have installed those, I would look into your PATH to make sure the appropriate ld utility is used.

Thanks will try both!

I did brew install llvm, but then got the same error. During the install, it did tell me to:
To use the bundled libc++ please add the following LDFLAGS:
LDFLAGS="-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib"

llvm is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have llvm first in your PATH, run:
  echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> ~/.zshrc

For compilers to find llvm you may need to set:
  export LDFLAGS="-L/usr/local/opt/llvm/lib"
  export CPPFLAGS="-I/usr/local/opt/llvm/include"

Not sure if I need to do anything with those in the Makefile(s)?

So with the caveat that I don’t know what our coworkers that use a mac have done, I would put those export lines in your rc file. In the case you are using zshell, as it says run echo '...' >> ~/.zshrc. In the case you are using bash, which is what I suspect, just swap the ‘.zshrc’ for ‘.bashrc’. I also think you need to do that for all three variables mentioned.

These are modifying your shell so that it can find the correct, just installed llvm version of ld binary before it finds the freebsd one that is included with your mac install. As such, you should make sure you have those environment variables in the appropriate rc file and then reload your shell. Probably by killing the current one and starting a new one. You can even double check the value is what it should be with echo $VAR in the new shell before running make again.

Looking over the makefile, I don’t see any reasoning going on in that file to point at different binaries, so hopefully it will work once those are set to compatible versions

Thanks! Will give that a try!

Thanks tried all the above but still the same error… when I did echo $VAR it did not return any info, not sure if that is relevant or not.

Oh sorry - I meant for you to run echo $PATH, echo $LDFLAGS, and echo $CPPFLAGS. The last two should match exactly what brew gave you in the printout. While echo $PATH will have more values than just what was printed out from brew.

So when you run:
echo $LDFLAGS you should get -L/usr/local/opt/llvm/lib,
echo $CPPFLAGS you should get -I/usr/local/opt/llvm/include,
echo $PATH the value you get should include /usr/local/opt/llvm/bin between : other paths. If /usr/local/opt/llvm/bin is at the end of PATH don’t worry about putting a : at the very end.

Again, this is just to check that those variables are defined in a new shell.

If not, then you will need to check your rc file again. Either ~/.zshrc or ~/.bashrc. It should include (probably at the end)

export PATH="/usr/local/opt/llvm/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/llvm/lib"
export CPPFLAGS="-I/usr/local/opt/llvm/include"

Hope that was a bit more clear.

Thanks!! Will give the above a try!

1 Like

Thanks again, unfortunately, still getting the same error. I checked all of the above:

Last login: Tue Mar 16 21:46:11 on ttys000
markstadtmueller@Tangram00186-MarkS ~ % cat .zshrc
export PATH="/usr/local/opt/llvm/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/llvm/lib"
export CPPFLAGS="-I/usr/local/opt/llvm/include"
markstadtmueller@Tangram00186-MarkS ~ % echo $LDFLAGS
-L/usr/local/opt/llvm/lib
markstadtmueller@Tangram00186-MarkS ~ % echo $CPPFLAGS
-I/usr/local/opt/llvm/include
markstadtmueller@Tangram00186-MarkS ~ % echo $PATH
/usr/local/opt/llvm/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
markstadtmueller@Tangram00186-MarkS ~ % cd location-reporter
markstadtmueller@Tangram00186-MarkS location-reporter % make libs=dynamic all

get the same error whether I run “make libs=dynamic all” or just “make all”

ld: unknown option: --copy-dt-needed-entries
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [build/libs/libTangramTransportZMQ.so] Error 1
make[1]: *** [build_deps] Error 2
make: *** [csi] Error 2

hmm I am kind of at a loss. I attempted to recreate the issue but ran into other issues. The only thing I can think of now is this line:

To use the bundled libc++ please add the following LDFLAGS:
LDFLAGS="-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib"

so looking through the Makefile, I can see where that rpath value gets added and can only think to add the /usr/local/opt/llvm/lib to that value.

But again, I am unsure of what our coworkers on mac are doing. It can’t be that they all modified the flags manually after the fact. Or at least I wouldn’t think?

Turning toward the docker build, I did find this SO question and answer that seems promising. But it again runs into the key only brew install issue where you would have to change some environment variables manually.

Sorry I can’t be more helpful. Perhaps we should pair to work through it? I feel like you are right at the precipice of getting it to work.

Thanks on all 3!. I will try both the makefile edit for the local and the stackoverflow post on libxml2 for docker. After that, will take you up on the pair (not to interfere with anything else), but will send an invite. Thanks!

With respect to libxml2, i found this: Troubles compiling or linking programs using libxml2

Usually the problem comes from the fact that the compiler doesn’t get the right compilation or linking flags. There is a small shell script xml2-config which is installed as part of libxml2 usual install process which provides those flags. Use

xml2-config --cflags

to get the compilation flags and

xml2-config --libs

to get the linker flags. Usually this is done directly from the Makefile as:

CFLAGS=xml2-config --cflags``

LIBS=xml2-config --libs``

I see CFLAGS in the Location-reporter Makefile, but not LIBS. Was wanting to give it a try. But, not sure if/where I should put these. Any thoughts? " See the libxml2 FAQ. If available on your system, pkg-config might give better results". http://xmlsoft.org/FAQ.html#Developer