wdas / ptex

Per-Face Texture Mapping for Production Rendering https://wdas.github.io/ptex

Home Page:https://www.disneyanimation.com/open-source/ptex/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Linux GCC link error for PtexReader::MetaData::getEntry after disabling static library builds

foundry-markf opened this issue · comments

Hello,

This error cropped up when disabling static library builds under GCC on Linux (various distros and GCC versions tested). Tested the v2.4.1 tag source.

We don't see a similar error on Windows and Mac, so it doesn't appear to be an issue with symbol visibility in shared libraries.

Here's reproducible steps (output from Ubuntu 20.04 and GCC 9 and CMake 3.22.3):

cmake -Bbuild -Ssrc -DPTEX_BUILD_STATIC_LIBS=OFF

gives

-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - yes
-- Found Threads: TRUE  
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1")
-- Checking for module 'zlib'
--   Found zlib, version 1.2.11
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
-- Configuring done
-- Generating done
-- Build files have been written to: /home/parallels/dev/ptex-test/build

then

make -C build -j2

giving

<omitted successful output>
[ 66%] Linking CXX executable ptxinfo
[ 76%] Built target rtest
make[2]: Entering directory '/home/parallels/dev/ptex-test/build'
Consolidate compiler generated dependencies of target ftest
make[2]: Leaving directory '/home/parallels/dev/ptex-test/build'
[ 85%] Built target ftest
make[2]: Entering directory '/home/parallels/dev/ptex-test/build'
make[2]: Leaving directory '/home/parallels/dev/ptex-test/build'
make[2]: Entering directory '/home/parallels/dev/ptex-test/build'
[ 90%] Building CXX object src/tests/CMakeFiles/halftest.dir/halftest.cpp.o
/usr/bin/ld: CMakeFiles/ptxinfo.dir/ptxinfo.cpp.o: in function `DumpMetaData(Ptex::v2_4::PtexMetaData*)':
ptxinfo.cpp:(.text+0xd6a): undefined reference to `Ptex::v2_4::PtexReader::MetaData::getEntry(int)'
/usr/bin/ld: ptxinfo.cpp:(.text+0xfbd): undefined reference to `Ptex::v2_4::PtexReader::MetaData::getEntry(int)'
/usr/bin/ld: ptxinfo.cpp:(.text+0x11cf): undefined reference to `Ptex::v2_4::PtexReader::MetaData::getEntry(int)'
/usr/bin/ld: ptxinfo.cpp:(.text+0x13df): undefined reference to `Ptex::v2_4::PtexReader::MetaData::getEntry(int)'
/usr/bin/ld: ptxinfo.cpp:(.text+0x15cb): undefined reference to `Ptex::v2_4::PtexReader::MetaData::getEntry(int)'
/usr/bin/ld: CMakeFiles/ptxinfo.dir/ptxinfo.cpp.o:ptxinfo.cpp:(.text+0x1832): more undefined references to `Ptex::v2_4::PtexReader::MetaData::getEntry(int)' follow
collect2: error: ld returned 1 exit status
make[2]: *** [src/utils/CMakeFiles/ptxinfo.dir/build.make:99: src/utils/ptxinfo] Error 1

The failing link command is this:

cd /home/parallels/dev/ptex-test/build/src/utils && /snap/cmake/1035/bin/cmake -E cmake_link_script CMakeFiles/ptxinfo.dir/link.txt --verbose=1
/usr/bin/c++  -Wall -Wextra -pedantic -O3 -DNDEBUG CMakeFiles/ptxinfo.dir/ptxinfo.cpp.o -o ptxinfo  -Wl,-rpath,/home/parallels/dev/ptex-test/build/src/ptex: ../ptex/libPtex.so.2.4 /usr/lib/x86_64-linux-gnu/libz.so -pthread

Is this something you've seen before?

Thanks,
Mark

I'm getting the same error. In my case I can just re-enable static builds on linux so thanks for the pointer!

Thanks for the heads-up. I suspect we need to mark getEntry or the MetaData class as a public exported symbol. I'm taking a look. We recently switched ptex over to use hidden visibility by default, so there's likely a spot or two where we have to add the PTEXAPI annotations.

Thanks @davvid.

I'm going to play devil's advocate for a moment. I would have expected Windows shared builds to be erroring about missing symbols if it was a visibility issue due to how that linker works. Linux is usually the more permissive when it comes to missing symbols in shared libs.

But perhaps there is something about the structure of the Ptex library that I'm missing that throws that intuition off?