-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
fix: fix symbol export on Windows + use target properties #922
Conversation
…27514) * [tinyxml2]: do not force export the symbols when building statically leethomason/tinyxml2#922 * [tinyxml2]: check for TINYXML2_EXPORT on non windows * [tinyxml2] avoid redefinition of TINYXML2_LIB
@aminya any thoughts / responses to @alexreinking comments? |
I already discussed many things in |
@aminya - but you have not replied to my review comments, which were written more recently. In particular, the |
TINYXML2_EXPORT is the gateway to forcing the symbol in the final shared library. What do you mean it is irrelevant? |
CMakeLists.txt
Outdated
DEFINE_SYMBOL "TINYXML2_EXPORT" # only used when tinyxml2_SHARED_LIBS/BUILD_SHARED_LIBS is ON | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So now there's an extra newline?
DEFINE_SYMBOL "TINYXML2_EXPORT" # only used when tinyxml2_SHARED_LIBS/BUILD_SHARED_LIBS is ON | |
DEFINE_SYMBOL "TINYXML2_EXPORT" |
Let's keep this change functional, please. We can discuss adding proper documentation for this later.
@aminya - I tried to reproduce the issue you were facing. Please tell me if any of the steps I followed differ from yours. Step 0: create a working directory
Now we have somewhere to work. Step 1: download, patch, and build tinyxml2
That last line applies the same change you made to Now we'll build tinyxml2 as a static library, with PIC enabled since it will be part of a shared library later.
We're installing it to Step 2: create a simple project:Create two files in
cmake_minimum_required(VERSION 3.23)
project(example)
find_package(tinyxml2 REQUIRED)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)
add_library(example SHARED example.cpp)
target_link_libraries(example PRIVATE tinyxml2::tinyxml2)
#include <tinyxml2.h>
using namespace tinyxml2;
__attribute__((visibility("default")))
int example()
{
static const char* xml = "<element/>";
XMLDocument doc;
doc.Parse( xml );
return doc.ErrorID();
} The build forces the Step 3: build the project
Here we set Now we can see that the only exported symbol is
We only care about the exported (capital), text ("T") symbols. Step 3b: trying againIf I repeat all the same steps as before but without the patch to
This shows that no changes to the CMakeLists.txt are necessary, but your change to the header file is good and correct. |
Thanks for the example. I moved the setting of the visibility properties of the tinyxml2 target to avoid any confusion. |
Please revert the changes to |
Closing. Can re-open if the thread picks back up. |
@leethomason This was ready to be merged. Are you closing this because of a simple documentation comment? |
@alexreinking had requested removing the changes to cmakelist.txt. There are still changes - were those intended? Is there any reason not to revert them? |
Yes, they were intended. The CMake hidden variable was being set globally, but this makes it specific to the |
@aminya -- I'm not sure what you mean by "globally". The variables would be local to the project, so if one were to Furthermore, this build has only one library ( Thus the changes to the |
With 240e5c1, the PR lost the |
I suggest you read the Effective Modern Cmake as it is the recommended approach by the CMake experts. |
I checked the documentation of CMake. Based on the doc, that check is done automatically for a target. |
I checked the documentation again now.
|
@aminya -- Please do not resort to insults. I posted a demonstration above showing that your header edit alone (which is good and worth merging!) is sufficient to address the symbol export issue. Please re-examine this and either:
@dg0yt - thank you for reading the documentation. The variables are indeed fine. They have the added benefit of applying to new targets within this project should the need ever arise; this reduces the risk of accidental symbol mismanagement.
IIUC - we actually don't want this. We want the non-API symbols to be hidden in static libraries. The header fix makes exactly the API symbols visible (by checking |
This changes the export definition to only happen when the tinyxml2 itself is built as a shared library.
It fixes an issue where the tinyxml2 symbols are exported even when it is compiled statically and privately linked into another shared library. This allows the compiler to inline these symbols. Otherwise, the symbols of tinyxml2 are exported in the final shared library.