Homebrew / legacy-homebrew

💀 The former home of Homebrew/homebrew (deprecated)
https://brew.sh
26.99k stars 11.36k forks source link

open-scene-graph build fails: iconv link error #46356

Closed mofoyoda closed 8 years ago

mofoyoda commented 8 years ago

I've got an error trying to build open-scene-graph

I'm building with: brew install --with-collada-dom --with-dcmtk --with-docs --with-ffmpeg --with-gdal --with-gnuplot --with-jasper --with-librsvg --with-openexr --verbose openscenegraph

and getting a make error here:

[ 72%] Building CXX object src/osgPlugins/shp/CMakeFiles/osgdb_shp.dir/ESRIShape.cpp.o
cd /tmp/open-scene-graph20151125-93815-cie49z/OpenSceneGraph-3.4.0/build/src/osgPlugins/shp && /usr/local/Library/ENV/4.3/clang++   -Dosgdb_shp_EXPORTS -I/tmp/open-scene-graph20151125-93815-cie49z/OpenSceneGraph-3.4.0/include -F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks -I/tmp/open-scene-graph20151125-93815-cie49z/OpenSceneGraph-3.4.0/build/include  -std=c++11 -stdlib=libc++  -Wno-conversion -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -fPIC   -o CMakeFiles/osgdb_shp.dir/ESRIShape.cpp.o -c /tmp/open-scene-graph20151125-93815-cie49z/OpenSceneGraph-3.4.0/src/osgPlugins/shp/ESRIShape.cpp
Undefined symbols for architecture x86_64:
  "__libiconv_version", referenced from:
      OFCharacterEncoding::getLibraryVersionString() in libofstd.a(ofchrenc.cc.o)
  "_libiconv", referenced from:
      OFCharacterEncoding::convertString(void*, char const*, unsigned long, OFString&, bool) in libofstd.a(ofchrenc.cc.o)
  "_libiconv_close", referenced from:
      OFCharacterEncoding::closeDescriptor(void*&) in libofstd.a(ofchrenc.cc.o)
  "_libiconv_open", referenced from:
      OFCharacterEncoding::openDescriptor(void*&, OFString const&, OFString const&) in libofstd.a(ofchrenc.cc.o)
  "_libiconvctl", referenced from:
      OFCharacterEncoding::convertString(void*, char const*, unsigned long, OFString&, bool) in libofstd.a(ofchrenc.cc.o)
  "_locale_charset", referenced from:
      OFCharacterEncoding::updateLocaleEncoding() in libofstd.a(ofchrenc.cc.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [lib/osgPlugins-3.4.0/osgdb_dicom.so] Error 1
make[1]: *** [src/osgPlugins/dicom/CMakeFiles/osgdb_dicom.dir/all] Error 2

any clues?

MikeMcQuaid commented 8 years ago

Sorry but you have not followed the requested steps on the Troubleshooting page: https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/Troubleshooting.md#troubleshooting

Please follow (all of) these steps and post the information here so we can help you with your problem.

Thanks!

apjanke commented 8 years ago

I can reproduce on 10.9.5.

Build logs: https://gist.github.com/32be25ac30ab554fbb5b

This was a build done with HOMEBREW_MAKE_JOBS=1 brew install -v --build-from-source open-scene-graph --with-collada-dom --with-dcmtk --with-docs --with-ffmpeg --with-gdal --with-gnuplot --with-jasper --with-librsvg --with-openexr.

Same error on 10.9.5 with the default options: HOMEBREW_MAKE_JOBS=1 brew install -v --build-from-source open-scene-graph

https://gist.github.com/e82958822cbdd78ec258

I also see the same error on 10.11 if I build OpenSceneGraph from its distribution outside Homebrew using its default options. I can't reproduce under Homebrew on 10.11 because it's failing due to #46372, which may be masking this issue.

apjanke commented 8 years ago

Okay.

Undefined symbols for architecture x86_64:
  "__libiconv_version", referenced from:
      OFCharacterEncoding::getLibraryVersionString() in libofstd.a(ofchrenc.cc.o)

From the build log, we can see that this is being pulled in from /usr/local/lib/libofstd.a.

/usr/local/Library/ENV/4.3/clang++   -std=c++11 ... /usr/local/lib/libofstd.a

That file is supplied by the dcmtk formula.

$ ls -la /usr/local/lib/libofstd.a
lrwxr-xr-x 1 janke admin 45 Nov 25 21:48 /usr/local/lib/libofstd.a -> ../Cellar/dcmtk/3.6.1-20150924/lib/libofstd.a

I think this means that the build command should also be linking against libiconv if it uses dcmtk. I'm not sure if that is something the formula should be supplying, or if it's an upstream issue with OSG's build system.

As a workaround, uninstalling dcmtk with brew rm dcmtk and not using --with-dcmtk seems to fix this. In that case for me, the build gets further and fails with #43536 instead. Removing collada-dom and --with-collada-dom then get it to build all the way.

mofoyoda commented 8 years ago

Removing --with-dcmtk option still results in the failing build with the same libiconv link error

apjanke commented 8 years ago

Did you also uninstall dcmtk with brew rm dcmtk or brew unlink dcmtk? If not, OSG's build script will still autodetect it and attempt to build against it.

apjanke commented 8 years ago

Looks like the issue is that OSG's build script for their dicom plugin assumes that dcmtk was not built against libiconv, so it doesn't attempt to link iconv. But dcmtk's build script autodetects libiconv, and since OS X ships with libiconv, it discovers and builds against it.

Seems like OSG should be querying dcmtk to see whether it was built with libiconv, or at least detecting libiconv on the system and assuming dcmtk was built against it if present, and include it in the libraries to link against.

We could patch it to link against libiconv. Though to be correct, we should check dcmtk to see whether it was built against the system libiconv or the Homebrew dupes libiconv, and link against the same one.

diff --git a/src/osgPlugins/dicom/CMakeLists.txt b/src/osgPlugins/dicom/CMakeLists.txt
index 55c2a57..e6e3f4a 100644
--- a/src/osgPlugins/dicom/CMakeLists.txt
+++ b/src/osgPlugins/dicom/CMakeLists.txt
@@ -5,7 +5,7 @@ IF  (DCMTK_FOUND)

     SET(TARGET_SRC ReaderWriterDICOM.cpp )

-    LINK_LIBRARIES(${DCMTK_LIBRARIES} ${ZLIB_LIBRARY})
+    LINK_LIBRARIES(${DCMTK_LIBRARIES} iconv ${ZLIB_LIBRARY})

     ADD_DEFINITIONS(-DUSE_DCMTK)

The dcmtk installation includes a lib/cmake/dcmtk/DCMTKConfig.cmake file which could be pulled in by the OSG CMake scripts to detect whether dcmtk was built with iconv. I don't know enough CMake to know how to pull that in, though.

mofoyoda commented 8 years ago

brew rm dcmtk works for me, thanks. Seems like no other formula is using it, so removing it doesn't affect anything except OSG. Still had to hardcode collada-dom path, because I need collada models support in OSG.

apjanke commented 8 years ago

Okay, here's a PR that will get OSG building even when dcmtk is installed, and should get --with-dcmtk working again. #46388

MikeMcQuaid commented 8 years ago

Looks like this should have been fixed. If not: we'll accept PRs for this but we're not actively working on it at this time.