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

FIX: fix link error when LIVE555_MONOLITH_BUILD is ON #11

Merged
merged 1 commit into from
Mar 4, 2025

Conversation

nonbanana
Copy link
Contributor

KO

cmake 프로젝트로 관리 해주시고 계셔서 감사합니다.
윈도우즈 에서 LIVE555_MONOLITH_BUILD을 ON으로 설정시 링크 에러가 발생하여 수정후 풀리퀘스트 드립니다.

현재 LIVE555_MONOLITH_BUILD을 ON으로 설정하면 live555를 의존성으로 추가한 cmake 프로젝트에 EpollTaskScheduler.obj와 live555.dll가 동시에 링크 됩니다. 이로 인해 정의가 중복되어 링크 에러가 발생하였습니다.

EpollTaskScheduler 정의가 중복되므로 target_link_libraries 구문을 제거하고 if (Target EpollTaskScheduler) 구문을 이용해 add_library에 EpollTaskScheduler가 포함되거나 포함되지 않도록 변경하였습니다.

아래 코드로 새 cmake 프로젝트를 만들고 재현해 볼 수 있습니다.

EN (translated by ChatGPT)

Thank you for managing the project with CMake.
When the LIVE555_MONOLITH_BUILD option is set to ON on Windows, a linking error occurs. I have fixed this and am submitting a pull request.

Currently, when LIVE555_MONOLITH_BUILD is set to ON, both EpollTaskScheduler.obj and live555.dll are linked simultaneously in a CMake project that depends on live555. This causes a linking error due to duplicate definitions.

To resolve this, I removed the target_link_libraries statement for EpollTaskScheduler and modified the code to use the if (Target EpollTaskScheduler) statement. This ensures that EpollTaskScheduler is included or excluded from add_library accordingly.

You can reproduce the issue with make new cmake project and use following code:

reproducible code

use cpm

CPMAddPackage(
    NAME live555
    GITHUB_REPOSITORY melchi45/live555
    GIT_TAG master
    OPTIONS "LIVE555_MONOLITH_BUILD ON" "LIVE555_BUILD_EXAMPLES OFF" 
)

add_library(foo STATIC main.cpp)
target_link_libraries(foo PUBLIC live555::live555)

or use fetch content

include(FetchContent)
FetchContent_Declare(
    live555
    GIT_REPOSITORY https://github.com/melchi45/live555.git
    GIT_TAG master
)
set(LIVE555_MONOLITH_BUILD ON CACHE INTERNAL "Build SHARED libraries")
FetchContent_MakeAvailable(live555)

add_library(foo STATIC main.cpp)
target_link_libraries(foo PUBLIC live555::live555)

Fix link error in windows when option LIVE555_MONOLITH_BUILD is ON.
- EpollTaskScheduler object was duplicated in live555 SHARED and INTERFACE
- delete EpollTaskScheduler in live555 INTERFACE (lgpl issue)
@nonbanana
Copy link
Contributor Author

It doesn't seem to be reproducible, so I will close this for now and verify the reproduction steps before reopening it.
재현 안되는것 같아서 close 하고 재현 방법을 다시 확인해서 다시 open 하겠습니다.

@nonbanana nonbanana closed this Feb 21, 2025
@melchi45
Copy link
Owner

melchi45 commented Feb 23, 2025 via email

@nonbanana
Copy link
Contributor Author

nonbanana/live555_test 링크에 재현 가능한 프로젝트 레포를 올려두었습니다. configure 전 vcpkg로 openssl 를 설치하신 뒤 아래처럼 configure 하시면 됩니다.

cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE="{VCPKG_ROOT}\\scripts\\buildsystems\\vcpkg.cmake" 

프로젝트 CMakeLists.txt 파일 CPMAddPackage 구문에 pull request 날린 레포를 주석으로 추가해두었으니 configure 된 프로젝트 파일을 지워가면서 테스트 해보시면 됩니다.

제가 테스트한 환경은 다음과 같습니다.

  • windows 11 21H2
  • MSVC 19.43.34808.0
  • cmake 3.31.5
    • generator: Visual Studio 17 2022
  • vcpkg
    • openssl

problem

LIVE555_MONOLITH_BUILD=ON 일때 EpollTaskScheduler의 처리가 이상합니다.

When use option "LIVE555_MONOLITH_BUILD ON" and "LIVE555_EPOLL_SUPPORT OFF"

if use live555 project in other cmake project

CPMAddPackage(
    NAME live555
    GITHUB_REPOSITORY melchi45/live555 #nonbanana/live555
    GIT_TAG master#fix/win-monolith-build
    OPTIONS "LIVE555_MONOLITH_BUILD ON" "LIVE555_BUILD_EXAMPLES OFF" "LIVE555_EPOLL_SUPPORT OFF"
)

or build directly

cmake -S . -B build -DLIVE555_MONOLITH_BUILD=ON -DLIVE555_EPOLL_SUPPORT=OFF

then, configure error ocure like this

CMake Error at {VCPKG_PATH}/scripts/buildsystems/vcpkg.cmake:618 (_add_library):
  Error evaluating generator expression:

    $<TARGET_OBJECTS:EpollTaskScheduler>

  Objects of target "EpollTaskScheduler" referenced but no such target
  exists.
Call Stack (most recent call first):
  CMakeLists.txt:286 (add_library)

When use option "LIVE555_MONOLITH_BUILD ON" and "LIVE555_EPOLL_SUPPORT ON"

import live555 project in other cmake project

CPMAddPackage(
    NAME live555
    GITHUB_REPOSITORY melchi45/live555 #nonbanana/live555
    GIT_TAG master#fix/win-monolith-build
    OPTIONS "LIVE555_MONOLITH_BUILD ON" "LIVE555_BUILD_EXAMPLES OFF" "LIVE555_EPOLL_SUPPORT ON"
)

and link library to other project in cmake

target_link_libraries(RTSPTest live555::live555)

then, build error (linker error) ocure like this

live555.lib(live555.dll) : error LNK2005: "public: class TaskScheduler & __cdecl UsageEnvironment::taskScheduler(void)const " (?taskScheduler@UsageEnvironment@@QEBAAE
AVTaskScheduler@@XZ)이(가) EpollTaskScheduler.obj에 이미 정의되어 있습니다. [C:\workspace\live555_test\build\RTSPTest.vcxproj]
     C:/workspace/live555_test/build/Debug/RTSPTest.lib 라이브러리 및 C:/workspace/live555_test/build/Debug/RTSPTest.exp 개체를 생성하고 있습니다.
C:\workspace\live555_test\build\Debug\RTSPTest.exe : fatal error LNK1169: 여러 번 정의된 기호가 있습니다. [C:\workspace\live555_test\build\RTSPTest.vcxproj]

@nonbanana nonbanana reopened this Feb 24, 2025
@melchi45 melchi45 merged commit a6b68a9 into melchi45:master Mar 4, 2025
6 of 11 checks passed
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 this pull request may close these issues.

None yet

2 participants