pkviet / obs-studio

OBS - Free and open source software for live streaming and screen recording
https://obsproject.com/mantis/
GNU General Public License v2.0
154 stars 21 forks source link

Linking error while building OBS without browser source #49

Closed vonorfasyexela closed 3 years ago

vonorfasyexela commented 3 years ago

Describe the bug I was building OBS Studio (your fork) from sources under freshly installed Ubuntu 20.04. I installed all necessary dependencies according the documentation and came to this part:

https://github.com/obsproject/obs-studio/wiki/Install-Instructions#linux-portable-mode-all-distros

Here I selected to build the application without browser source. That is for cmake I used the following command:

$ cmake -DUNIX_STRUCTURE=0 -DCMAKE_INSTALL_PREFIX="${HOME}/obs-studio-portable" ..

Then, after configuration I ran make and got the following linker error:

[ 92%] Linking CXX executable obs
/usr/bin/ld: CMakeFiles/obs.dir/window-basic-main.cpp.o: in function `OBSBasic::OBSBasic(QWidget*)':
/home/alexey/obs-studio/UI/window-basic-main.cpp:204: undefined reference to `RegisterTwitchAuth()'
collect2: error: ld returned 1 exit status
make[2]: *** [UI/CMakeFiles/obs.dir/build.make:1384: UI/obs] Error 1
make[1]: *** [CMakeFiles/Makefile2:1818: UI/CMakeFiles/obs.dir/all] Error 2
make: *** [Makefile:152: all] Error 2

Desktop (please complete the following information):

Additional context I made some investigation of this issue. It turned out that it is building successfully only with browser source. That is with this cmake command:

$ cmake -DUNIX_STRUCTURE=0 -DCMAKE_INSTALL_PREFIX="${HOME}/obs-studio-portable" -DBUILD_BROWSER=ON -DCEF_ROOT_DIR="../../cef_binary_4280_linux64" ..

These two cases differ in this option: -DBUILD_BROWSER=ON. I wondered what changes in this fork could lead to such behaviour. And found this commit: https://github.com/obsproject/obs-studio/commit/05d8c2025358c88af64c853f06c55aef2f9a2910

So here it simply sets TWITCH_ENABLED variable into TRUE without any conditions:

if(NOT DEFINED TWITCH_CLIENTID OR "${TWITCH_CLIENTID}" STREQUAL "" OR
   NOT DEFINED TWITCH_HASH     OR "${TWITCH_HASH}"     STREQUAL "" OR
   NOT BROWSER_AVAILABLE_INTERNAL)
    set(TWITCH_ENABLED FALSE)
    set(TWITCH_CLIENTID "")
    set(TWITCH_HASH "0")
else()
    set(TWITCH_ENABLED TRUE)
endif()

set(TWITCH_ENABLED TRUE)

This change leads to executing this part of code:

#if TWITCH_ENABLED
    RegisterTwitchAuth();
#endif

The function RegisterTwitchAuth() is defined in file auth-twitch.cpp, but this file adding to the codebase conditionally (only when BROWSER_AVAILABLE_INTERNAL=ON and TWITCH_ENABLED=ON):

if(BROWSER_AVAILABLE_INTERNAL)
    …
    if(TWITCH_ENABLED)
        list(APPEND obs_PLATFORM_SOURCES
            auth-twitch.cpp
            )
        list(APPEND obs_PLATFORM_HEADERS
            auth-twitch.hpp
            )
    endif()
    …
endif()

The variable BROWSER_AVAILABLE_INTERNAL is only set to ON when we provide -DBUILD_BROWSER=ON according to this:

if (BUILD_BROWSER)
    if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/obs-browser/CMakeLists.txt")
        add_subdirectory(obs-browser)
        set(BROWSER_AVAILABLE_INTERNAL ON CACHE BOOL "Internal global cmake variable" FORCE)
    else()
        message(STATUS "obs-browser submodule not found!  Please fetch submodules.  obs-browser plugin disabled.")
        set(BROWSER_AVAILABLE_INTERNAL OFF CACHE BOOL "Internal global cmake variable" FORCE)
    endif()
else()
    set(BROWSER_AVAILABLE_INTERNAL OFF CACHE BOOL "Internal global cmake variable" FORCE)
endif()

In our case only TWITCH_ENABLED=ON and this file is not included into the list of sources. And that's why the building system doesn't see it and gives an error.

pkviet commented 3 years ago

It's correct. That's the Twitch integration for browser panels. It requires obs-browser. I don't build for linux so I didn't ifdef that part. At the time there was no good linux browser support. If you don't need the Twitch integration, just disable it.

On Wed, Mar 3, 2021, 00:46 Alexey Safronov notifications@github.com wrote:

Describe the bug I was building OBS Studio (your fork) from sources under freshly installed Ubuntu 20.04. I installed all necessary dependencies according the documentation and came to this part:

https://github.com/obsproject/obs-studio/wiki/Install-Instructions#linux-portable-mode-all-distros

Here I selected to build the application without browser source. That is for cmake I used the following command:

$ cmake -DUNIX_STRUCTURE=0 -DCMAKE_INSTALL_PREFIX="${HOME}/obs-studio-portable" ..

Then, after configuration I ran make and got the following linker error:

[ 92%] Linking CXX executable obs

/usr/bin/ld: CMakeFiles/obs.dir/window-basic-main.cpp.o: in function `OBSBasic::OBSBasic(QWidget*)':

/home/alexey/obs-studio/UI/window-basic-main.cpp:204: undefined reference to `RegisterTwitchAuth()'

collect2: error: ld returned 1 exit status

make[2]: *** [UI/CMakeFiles/obs.dir/build.make:1384: UI/obs] Error 1

make[1]: *** [CMakeFiles/Makefile2:1818: UI/CMakeFiles/obs.dir/all] Error 2

make: *** [Makefile:152: all] Error 2

Desktop (please complete the following information):

  • OS: Ubuntu
  • Version 20.04.2

Additional context I made some investigation of this issue. It turned out that it is building successfully only with browser source. That is with this cmake command:

$ cmake -DUNIX_STRUCTURE=0 -DCMAKE_INSTALL_PREFIX="${HOME}/obs-studio-portable" -DBUILD_BROWSER=ON -DCEF_ROOT_DIR="../../cef_binary_4280_linux64" ..

These two cases differ in this option: -DBUILD_BROWSER=ON. I wondered what changes in this fork could lead to such behaviour. And found this commit: obsproject@05d8c20 https://github.com/obsproject/obs-studio/commit/05d8c2025358c88af64c853f06c55aef2f9a2910

So here it simply sets TWITCH_ENABLED variable into TRUE without any conditions. This change leads to executing this part of code:

if TWITCH_ENABLED

RegisterTwitchAuth();

endif

The function RegisterTwitchAuth() is defined in file auth-twitch.cpp, but this file adding to the codebase conditionally (only when BROWSER_AVAILABLE_INTERNAL=ON and TWITCH_ENABLED=ON):

if(BROWSER_AVAILABLE_INTERNAL)

if(TWITCH_ENABLED)

  list(APPEND obs_PLATFORM_SOURCES

      auth-twitch.cpp

      )

  list(APPEND obs_PLATFORM_HEADERS

      auth-twitch.hpp

      )

endif()

endif()

In our case only TWITCH_ENABLED=ON and this file is not included into the list of sources. And that's why the building system doesn't see it and gives an error.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/pkviet/obs-studio/issues/49, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACG2OT7HEHRLFBFJUVWIX23TBV2E5ANCNFSM4YP6MFEQ .

vonorfasyexela commented 3 years ago

Ok, thanks for a quick response.