Matroska-Org / libmatroska

a C++ libary to parse Matroska files (.mkv and .mka)
GNU Lesser General Public License v2.1
324 stars 57 forks source link

how do I actually statically link this with my project? #201

Open AstonishedByTheLackOfCake opened 3 months ago

AstonishedByTheLackOfCake commented 3 months ago

Hi, I wanted to read some .mkv metadata and discovered the existence of this library, but the instructions seemed very sparse

I managed to compile libebml.a, which I then used to produce libmatroska.a, but when I later tried using these in my actual project I can't for the life of me get it to work

I have both ebml and matroska headers in their respective folders in my project root, but I'm having issues with including FileKax.h, even though it's in the same directory as the other matroska headers (including matroska-export.h), it appears grayed-out in my IDE

FileKax.h seems to complain that it can't resolve \class MATROSKA_DLL_API FileMatroska and my main.cpp also complains that KaxCuePoint is incomplete (though, I'm guessing that's mostly due to the missing FileKax.h)

I don't really know what to do here, because it otherwise seems to recognise the presence of the static .a libraries, and it is just that one header file that's somehow broken

I am running windows and all the required files should be in my projects source directory

Any help would be greatly appreciated

robUx4 commented 2 months ago

Hi,

The project(s) are meant to be build with CMake and integrated that way. If you use another build system we can't tell what you're doing wrong. If you use Visual Studio on Windows it is capable of including CMake projects into your own project (at least if your project is a CMake based). Otherwise with CMake you can generate the .vcxproj files that you include into your own project.

AstonishedByTheLackOfCake commented 2 months ago

Hello, and thank you for responding

I am using Intellij's CLion, which is CMake based

I've made a more detailed post on stackoverfow regarding my setup (which has unfortunately yet to be answered)

I am fairly new to C++ and CMake in general, but I'm pretty sure that I configured my CMakeLists.txt to link with both libmatroska and libebml static libraries, and the issue is specifically when trying to import and use FileKax.h

I've previously managed to successfully link with ffmpeg's libavcodec, compiled as a dynamic link library, and never had any issues with not being able to simply just use any provided header files as long as I told cmake where to find the required libraries

my CMakeLists.txt looks like:

cmake_minimum_required(VERSION 3.28)
project(mkv_metadata_test)

set(CMAKE_CXX_STANDARD 26)

include_directories(${CMAKE_CURRENT_SOURCE_DIR})

set(EBML_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ebml")
set(MATROSKA_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/matroska")

include_directories(${EBML_INCLUDE_DIR} ${MATROSKA_INCLUDE_DIR})

set(EBML_LIBRARY "${CMAKE_CURRENT_SOURCE_DIR}/libebml.a")
set(MATROSKA_LIBRARY "${CMAKE_CURRENT_SOURCE_DIR}/libmatroska.a")

add_executable(mkv_metadata_test main.cpp)

target_link_libraries(mkv_metadata_test ${EBML_LIBRARY} ${MATROSKA_LIBRARY})

target_compile_definitions(mkv_metadata_test PRIVATE MATROSKA_STATIC_DEFINE) 

and the test project's structure is as simple as: M64N5bUp

where the ebml and matroska directories contain all of the headers for their respective libraries (including the -export.h generated when compiling the static .a libraries w/ cmake)

I'm probably just doing something stupid here due to my unfamiliarity w/ cmake