在Windows上使用msys2工具和cmake编译mp3lame项目

时间:2018-11-16 04:22:02

标签: cmake pthreads mingw-w64 msys2 lame

在使用这些cmake脚本进行了多次尝试之后,我最终得到了未定义的引用链接错误:

C:\msys64\tmp\ccRsIxEJ.ltrans0.ltrans.o:<artificial>:(.text+0x69a): undefined reference to `lame_init'
C:\msys64\tmp\ccRsIxEJ.ltrans0.ltrans.o:<artificial>:(.text+0x6aa): undefined reference to `lame_set_in_samplerate'
C:\msys64\tmp\ccRsIxEJ.ltrans0.ltrans.o:<artificial>:(.text+0x6b7): undefined reference to `lame_set_VBR'

我想cmake找不到我可以在"/mingw64/lib"上找到的mp3lame libray

这是我正在使用的两个cmake脚本:

cmake_minimum_required(VERSION 3.1)
project(converter)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(THREADS_PREFER_PTHREAD_FLAG ON)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".so")
set(CMAKE_EXE_LINKER_FLAGS "-flto")
set(CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} -O2 --std=c++14 -Wall -flto" )

enable_language(CXX)

find_package(Lame REQUIRED)
find_package (Threads REQUIRED)
set(LIBS ${LIBS} ${LAME_LIBRARIES} Threads::Threads)
include_directories(${LAME_INCLUDE_DIRS})
add_executable(converter src/converter.cpp src/pthreadmanager.cpp)
target_link_libraries(converter ${LIBS})

和第二个应该定位la脚的依赖项:

# - Try to find LAME
# Once done this will define
#
# LAME_FOUND - system has liblame
# LAME_INCLUDE_DIRS - the liblame include directory
# LAME_LIBRARIES - The liblame libraries

#find_path(LAME_INCLUDE_DIRS lame/lame.h HINTS /mingw64/include)
#find_library(LAME_LIBRARIES mp3lame HINTS /mingw64/lib)
#The previous two instructions do not work so I set LAME_INCLUDE_DIRS and LAME_LIBRARIES manually I even tried without the HINTS but still not working
set(LAME_INCLUDE_DIRS "/mingw64/include/lame")
set(LAME_LIBRARIES "/mingw64/lib")

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Lame DEFAULT_MSG LAME_INCLUDE_DIRS LAME_LIBRARIES)

list(APPEND LAME_DEFINITIONS -DHAVE_LIBMP3LAME=1)

mark_as_advanced(LAME_INCLUDE_DIRS LAME_LIBRARIES LAME_DEFINITIONS)

我的lib文件夹同时包含libmp3lame.a和libmp3lame.dll.a文件

如果您有任何解决办法,请在Debian(linux)上运行良好。

0 个答案:

没有答案