[sfml] Declare Windows library export#9190
Conversation
|
/azp run |
2 similar comments
|
/azp run |
|
/azp run |
|
Are you sure this patches the problem? For static libraries, CMake handles the PRIVATE dependencies and exports them downstream......... This patch should be unnecessary? |
|
@cenit According to the cmake documentation, if we declare a dependency as |
|
@JackBoosY cmake documentation might be deceiving In fact, just an inspection of the configs would tell you the truth: in case you build a static library, private dependencies are exported downstream no matter what |
|
This patch is technically wrong, but practically makes it easier for the user. The issue is that vcpkg links all the libraries in the vcpkg lib paths, but since winmm and gdi32 arr system libraries and thus not in the vcpkg lib paths, they aren't linked automatically and need to be added manually. Or rather if you use CMake you just need to call find_package and link SFML as part of CMake. See conversation on Slack: https://cpplang.slack.com/archives/C7BFF7RCJ/p1574294173361500 |
|
what's the relationship between vs autolinking using vcpkg and cmake? also: is this patch really fixing anything? This is what I doubt! Can you give me a test case failing before and having success now? |
|
For the original bug and the followed discussion I always assumed that the reporter was using CMake to generate the VS project, but they really just installed SFML and used vcpkg autolinking integration, thus system libs aren't linked, but are required when statically linking.
That's a good question. If the user isn't using CMake to generate a VS project, I don't think that this changes anything and if they do, then it was already working correctly. As such, I'd also say that this doesn't actually "fix" anything. |
The documentation is not very explicit when it comes to shared vs static linking, but I've tested this myself and for static linking the PRIVATE libraries are linked in the final version. Additionally, this has been confirmed and explained independently by others (e.g. here). |
|
@cenit Windows system libraries are special. Because the paths of the libraries installed with Visual Studio are not consistent, the compiler will not add the addresses of these libraries to the static libraries that depend on it, which leads us to manually declare and link these system libraries. The usual approach is to force the system libraries to be declared in the link sequence when building a static library that depends on it, but I think this PR approach is better (more concise). |
@JackBoosY i think you are misunderstanding the problem (and maybe a little bit more knowledge would be appropriate, because i think there is nothing correct in your message at least regarding the problem here @ras0219-msft ). Please try to build the sfml project before and after your patch. |
|
Hello, sorry for a late response. I'm the original reporter of #8864. I can confirm the issue is not fixed. I'm getting exactly the same linking problems. I think we should re-open #8864. |
|
I have the same problem, trying to statically link results in unresolved external symbol errors. |
|
As stated you have to link the system dependencies yourself. |
|
@JackBoosY @strega-nil please also remove the unnecessary patch introduced by this merged PR |
Ok, my previous understanding was that all system dependencies were added to the additional dependencies by default in VS or vcpkg would/should cover me on that front. Thanks for your time and effort. |
|
gdi32.lib is by default part of the Additiona Libraries that Visual Studio links. I'm not familiar enough with vcpkg to know whether there are options to add system libraries to the recipe. |
When using sfml, the custom project should also link to winmm.lib and gdi32.lib, so change the linking method of these two libraries to public.
Related: #8864.