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

[openexr] errors when linking to static library #2596

Closed
atkawa7 opened this issue Jan 17, 2018 · 4 comments
Closed

[openexr] errors when linking to static library #2596

atkawa7 opened this issue Jan 17, 2018 · 4 comments
Labels
requires:repro The issue is not currently repro-able

Comments

@atkawa7
Copy link
Contributor

atkawa7 commented Jan 17, 2018

@codicodi @ras0219-msft @alexkaratarakis Came across an issue similar to #1279
when linking to openexr static library. I am not sure why its looking for symbols when I am using the static libs. I looked at the export macros. There seem to be no issue. Could there be something in the way I am consuming this port.

IlmImf-2_2.lib(ImfTileOffsets.cpp.obj) : error LNK2001: unresolved external symbol "public: __thiscall Iex_2_2::BaseExc::BaseExc(char const *)" (??0BaseExc@Iex_2_2@@QAE@PBD@Z)
IlmImf-2_2.lib(ImfFastHuf.cpp.obj) : error LNK2001: unresolved external symbol "public: __thiscall Iex_2_2::BaseExc::BaseExc(char const *)" (??0BaseExc@Iex_2_2@@QAE@PBD@Z)
IlmImf-2_2.lib(ImfDeepTiledInputFile.cpp.obj) : error LNK2001: unresolved external symbol "public: __thiscall Iex_2_2::BaseExc::BaseExc(char const *)" (??0BaseExc@Iex_2_2@@QAE@PBD@Z)
IlmImf-2_2.lib(ImfDeepFrameBuffer.cpp.obj) : error LNK2001: unresolved external symbol "public: __thiscall Iex_2_2::BaseExc::BaseExc(char const *)" (??0BaseExc@Iex_2_2@@QAE@PBD@Z)
IlmImf-2_2.lib(ImfMultiPartInputFile.cpp.obj) : error LNK2001: unresolved external symbol "public: __thiscall Iex_2_2::BaseExc::BaseExc(char const *)" (??0BaseExc@Iex_2_2@@QAE@PBD@Z)
IlmImf-2_2.lib(ImfCompositeDeepScanLine.cpp.obj) : error LNK2001: unresolved external symbol "public: __thiscall Iex_2_2::BaseExc::BaseExc(char const *)" (??0BaseExc@Iex_2_2@@QAE@PBD@Z)
IlmImf-2_2.lib(ImfDeepScanLineInputFile.cpp.obj) : error LNK2001: unresolved external symbol "public: __thiscall Iex_2_2::BaseExc::BaseExc(char const *)" (??0BaseExc@Iex_2_2@@QAE@PBD@Z)
IlmImf-2_2.lib(ImfTiledMisc.cpp.obj) : error LNK2001: unresolved external symbol "public: __thiscall Iex_2_2::BaseExc::BaseExc(char const *)" (??0BaseExc@Iex_2_2@@QAE@PBD@Z).

These symbols are related to these lines

class BaseExc: public std::string, public std::exception
{
  public:

    //----------------------------
    // Constructors and destructor
    //----------------------------

    IEX_EXPORT BaseExc (const char *s = 0) throw();     // std::string (s)
    IEX_EXPORT BaseExc (const std::string &s) throw();  // std::string (s)
    IEX_EXPORT BaseExc (std::stringstream &s) throw();  // std::string (s.str())

    IEX_EXPORT BaseExc (const BaseExc &be) throw();
    IEX_EXPORT virtual ~BaseExc () throw ();
}

Based on this ticket AcademySoftwareFoundation/openexr/issues/86 I see why extending strings is problematic when it comes exports. However shouldn't this work in static form?

@ras0219-msft
Copy link
Contributor

I'm not seeing any issue in MSBuild:

// main.cpp
#include <OpenEXR\IexBaseExc.h>

int main(int argc, char * argv[])
{
    throw Iex_2_2::BaseExc("hello");
}

builds and links successfully (and the resulting executable doesn't depend on any DLLs). Is it possible you're accidentally not linking the lib file?

Otherwise, could you share a full repro (code+build)?

@atkawa7
Copy link
Contributor Author

atkawa7 commented Jan 18, 2018

@ras0219-msft Here is example code.
exrtools.zip

@ras0219-msft
Copy link
Contributor

Here's my setup that (mostly) works:

vcpkg install openexr:x64-windows-static

Then, in the cmake file I added the following to use /MT

project(exrtools C CXX)

string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}" CACHE STRING "" FORCE)
string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING "" FORCE)

string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}" CACHE STRING "" FORCE)
string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" CACHE STRING "" FORCE)

Upon building, I got a bunch of zlib link errors (missing compress2 and uncompress). I therefore edited FindOpenEXR.cmake and added ZLIB::ZLIB to the OpenEXR_LIBRARIES variable.

Once I did that, most of the binaries compile and link fine. I still get these errors:


"D:\src\exrtools\build\ALL_BUILD.vcxproj" (default target) (1) ->
"D:\src\exrtools\build\exrpptm.vcxproj" (default target) (8) ->
(ClCompile target) ->
  d:\src\exrtools\exrpptm.c(35): fatal error C1083: Cannot open include file: 'values.h': No such file or directory [D:\src\exrtools\build\exrpptm.vcxproj]


"D:\src\exrtools\build\ALL_BUILD.vcxproj" (default target) (1) ->
"D:\src\exrtools\build\exrtopng.vcxproj" (default target) (10) ->
  d:\src\exrtools\pngoutput.c(93): error C2065: 'Z_BEST_COMPRESSION': undeclared identifier [D:\src\exrtools\build\exrtopng.vcxproj]


"D:\src\exrtools\build\ALL_BUILD.vcxproj" (default target) (1) ->
"D:\src\exrtools\build\ppmtoexr.vcxproj" (default target) (13) ->
(Link target) ->
  ppmtoexr.obj : error LNK2019: unresolved external symbol ntohs referenced in function main [D:\src\exrtools\build\ppmtoexr.vcxproj]
  D:\src\exrtools\build\Debug\ppmtoexr.exe : fatal error LNK1120: 1 unresolved externals [D:\src\exrtools\build\ppmtoexr.vcxproj]

but none of them match the errors you're getting.

@ras0219-msft ras0219-msft added the requires:repro The issue is not currently repro-able label Jan 18, 2018
@atkawa7
Copy link
Contributor Author

atkawa7 commented Jan 18, 2018

@ras0219-msft Managed to fix by doing a clean install. See #2599

@atkawa7 atkawa7 closed this as completed Jan 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
requires:repro The issue is not currently repro-able
Projects
None yet
Development

No branches or pull requests

2 participants