Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]Fail to build static library #2361

Closed
JackBoosY opened this issue Oct 11, 2019 · 3 comments · Fixed by #2442
Closed

[BUG]Fail to build static library #2361

JackBoosY opened this issue Oct 11, 2019 · 3 comments · Fixed by #2442

Comments

@JackBoosY
Copy link

JackBoosY commented Oct 11, 2019

Hi Developers,
Recently, I tried to upgrade openimageio to the latest version in vcpkg(#8543), but there were some errors in the static build.

Describe the bug

timer.cpp(15): error C2491: 'OpenImageIO_v2_1::Timer::seconds_per_tick': definition of dllimport static data member not allowed
benchmark.cpp(35): error C2491: 'OpenImageIO_v2_1::clobber': definition of dllimport function not allowed
benchmark.cpp(116): error C2491: 'OpenImageIO_v2_1::operator <<': definition of dllimport function not allowed
...

After looking at the code, I found that the declaration of these functions is marked as OIIO_API, and this macro is defined as OIIO_EXPORT/OIIO_IMPORT in export.h:57-61, however its conditions OpenImageIO_EXPORTS and OpenImageIO_Util_EXPORTS are not defined in any cmake files, and I removed the declaration of seconds_per_tick under static build.

Then I defined these macros in SOURCE_PATH/CMakeLists.txt according to BUILD_SHARED_LIBS, and the following error occurred after rebuilding:

timer.h(171): error C2597: illegal reference to non-static member 'OpenImageIO_v2_1::Timer::seconds_per_tick'
timer.h(171): error C3867: 'OpenImageIO_v2_1::Timer::seconds_per_tick': non-standard syntax; use '&' to create a pointer to member

Put the initialization of seconds_per_tick into the constructor of class Timer.
Remove the static declaration from the static build in Timer::seconds. Then rebuild:

timer.h(157): error C2662: 'double OpenImageIO_v2_1::Timer::seconds(OpenImageIO_v2_1::Timer::ticks_t)': cannot convert 'this' pointer from 'const OpenImageIO_v2_1::Timer' to 'OpenImageIO_v2_1::Timer &'
timer.cpp(15): error C2761: 'double OpenImageIO_v2_1::Timer::seconds_per_tick': redeclaration of member is not allowed
timer.cpp(26): error C2597: illegal reference to non-static member 'OpenImageIO_v2_1::Timer::seconds_per_tick'

After looking at the constructor of the class TimerSetupOnce, I found that the seconds_per_tick was called here, but the instance pointer of the class Timer was not imported, which caused the Timer::seconds_per_tick not to be called here.

To Reproduce
Steps to reproduce the behavior:

  1. Clone vcpkg from this repo.
  2. ./bootstrap.bat
  3. ./vcpkg.exe install openimageio:x64-windows-static

Expected behavior
Build successful.

Evidence
See the details above.

Platform information:

  • OIIO branch/version: master - 781bc97
  • OS: Windows 10 Enterprise 1903
  • C++ compiler: Visual Studio 2017 ver 15.9.13
  • Any non-default build flags when you build OIIO:
    See changes here.

Can anyone help me?

Thanks.

@JackBoosY
Copy link
Author

After add -DOIIO_STATIC_DEFINE=1 to SOURCE/src/cmake/compiler.cmake line 454, this issue solved.

@lgritz
Copy link
Collaborator

lgritz commented Dec 25, 2019

aha, very interesting! I see the typo now...

@lgritz
Copy link
Collaborator

lgritz commented Dec 25, 2019

Proper fix in #2442

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants