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

BUILD_SHARED_LIBS & POCO_STATIC cause #pragma comment(lib, "PocoUtil" POCO_LIB_SUFFIX) to be invalid #4754

Open
athaa opened this issue Oct 31, 2024 · 6 comments
Assignees
Labels
buildsystem cmake Related to cmake build system platform_specific

Comments

@athaa
Copy link

athaa commented Oct 31, 2024

Hello Poco Team,

Describe the bug
The visual studio compiler/linker ask for Foundation.lib instead of Foundationmd.lib

To Reproduce
I build poco from source, as static, with cmake, using BUILD_SHARED_LIBS =OFF. I keep MT=OFF (to use system/compiler dll).
I got files ending with md.lib and mdd.lib => this is what I expected

I add lib and include dependencies to my project (visual studio) using cmake
I add
#include "Foundation.h"
in the main

call compiler OK
call linker NOT OK

Expected behavior

The linker shoud ask for PocoFoundationmd.lib, not for :
Logs

LINK : fatal error LNK1104: cannot open file 'PocoFoundation.lib'

Please add relevant environment information:

  • Windows 10
  • POCO 13.3, from what I can see the same problem should apply to the last version (main)

Additional context
From what I can see it is due to the check performed in Foundation.h

#if defined(_WIN32) && defined(_DLL)
	#if !defined(POCO_DLL) && !defined(POCO_STATIC)
		#define POCO_DLL
	#endif
#endif

It cause the following:
#pragma comment(lib, "PocoUtil" POCO_LIB_SUFFIX)
To be invalid (and all similar #pragma) since POCO_LIB_SUFFIX is created using POCO_DLL.

I supposed it should not use POCO_STATIC here because it is deprecated according the cmakefile:
message(WARNING "POCO_STATIC has been deprecated. Please use BUILD_SHARED_LIBS=NO to build static libraries.")
, but use BUILD_SHARED_LIBS (or a combination of both until complete removal)

BTW, I know the documentation :https://docs.pocoproject.org/current/99150-WindowsPlatformNotes.html
ask to use POCO_STATIC, but I guess the code is supposed to be more up to date. I'm right ?

Sorry if I miss something obvious.

Thanks by advance,

Have a good day

@matejk
Copy link
Contributor

matejk commented Nov 7, 2024

Dear @athaa, can you test if the changes on the branch 4754-cmake-windows-static-build (PR #4762) solve the problem?

@matejk matejk moved this to In Progress in 1.14 Nov 7, 2024
@athaa
Copy link
Author

athaa commented Nov 8, 2024

Dear Matejk,
Thank you
I don't have time to test righ now.
But I will surely give you feedback about your new branch.

@athaa
Copy link
Author

athaa commented Nov 12, 2024

Ok I just tested and the behaviour is the same. The linker is still asking for 'PocoFoundation.lib' and not 'PocoFoundationmd.lib'

Can you clarify one point:
The generated include folder is dependent on what option you choose (not the same folder size).
But does it set POCO_STATIC or BUILD_SHARED_LIBS ? It is what I assume.
Or does I have to set it manually in the final appplication build configuration ?

@matejk
Copy link
Contributor

matejk commented Nov 12, 2024

So, if I understand correctly, you

  1. build and install Poco
  2. build your project using CMake by including provided Poco CMake files

Is this correct?

@athaa
Copy link
Author

athaa commented Nov 13, 2024

not sure what you mean exactly by "Poco CMake files", I

  1. build and install Poco using provided cmake (which generate visual studio solution)
  2. build my project using my own cmake (which generate visual studio solution). In my cmake I use :
target_include_directories(${PROJECT_NAME}
        ...
	PUBLIC ${POCO_INCLUDE_DIR}
)

and:

target_link_libraries(${PROJECT_NAME}
	PUBLIC "$<$<CONFIG:Debug>:${POCO_LIBS_DEBUG}>$<$<CONFIG:Release>:${POCO_LIBS_RELEASE}>" 
	iphlpapi
	ws2_32
)

But the target link library configuration seems useless for Poco due to #pragma comment(lib, "PocoXXX" POCO_LIB_SUFFIX) presence in header file.

It has to be noted that currently I have fixed the linker issue defining POCO_STATIC in my project build configuration (not in POCO build where I use BUILD_SHARED_LIBS=OFF).
Im not sure what will be the way to use it when you will definitively switch to BUILD_SHARED_LIBS ?
Maybe I missunderstand what you intent to do with BUILD_SHARED_LIBS/ POCO_STATIC...

@matejk
Copy link
Contributor

matejk commented Nov 13, 2024

@athaa, when installing Poco after compiling it creates CMake files that you shall use in your project to use Poco with CMake using find_package like:

find_package(Poco REQUIRED COMPONENTS Foundation Net)

Poco CMake files are generated according to the specified configuration, including BUILD_SHARED_LIBS.

If compiling and linking using this way doesn't work properly then we shall investigate the cause.

@matejk matejk modified the milestones: Release 1.14.0, Release 1.15.0 Nov 18, 2024
@matejk matejk removed this from 1.14 Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
buildsystem cmake Related to cmake build system platform_specific
Projects
None yet
Development

No branches or pull requests

3 participants