[CMake] connect libraries to project with cmakelists

Michaila Goula-Dimitriou mixagd777 at gmail.com
Thu Oct 29 11:00:26 EDT 2015


I am using the cmakelists.txt below, that exists in the top folder of my
project, and I am trying to connect mpg123 and ao to my project. In one
.cpp file of the source folder I added a code with mpg123 and ao to play a
song. This code can be compiled with this line:

*g++ mpg.cpp -lmpg123 -lao -o mpg*

I also added this line:

target_link_libraries(emotime ${LIBAO_LIBRARIES} ${MPG123_LIBRARIES})

in the cmakelists that exists in my source folder. When I am running make I
get errors like "undefined reference to `ao_initialize'" and "undefined
reference to `mpg123_init'". Am I doing something wrong?

cmake_minimum_required(VERSION 2.8)

project(emotime)


find_package(OpenCV REQUIRED)

include_directories(${OpenCV_INCLUDE_DIRS})


FIND_PATH( MPG123_INCLUDE_DIR1

  NAMES mpg123.h

  PATH_SUFFIXES include

  PATHS

  ~/Library/Frameworks

  /Library/Frameworks

  /usr/local

  /usr

  /sw # Fink

  /opt/local # DarwinPorts

  /opt/csw # Blastwave

  /opt

  extern/mpg123/ports/MSVC++

  extern/mpg123/ports/Xcode

)


IF( MPG123_INCLUDE_DIR1 )

  SET( MPG123_INCLUDE_DIRS ${MPG123_INCLUDE_DIRS} ${MPG123_INCLUDE_DIR1} )

ENDIF( MPG123_INCLUDE_DIR1 )


# Include dir (May not be necessary on all platforms)

FIND_PATH( MPG123_INCLUDE_DIR2

  NAMES mpg123.h.in

  PATHS

  ~/Library/Frameworks

  /Library/Frameworks

  /usr/local

  /usr

  /sw # Fink

  /opt/local # DarwinPorts

  /opt/csw # Blastwave

  /opt

  extern/mpg123/src/libmpg123

)


IF( MPG123_INCLUDE_DIR2 )

  SET( MPG123_INCLUDE_DIRS ${MPG123_INCLUDE_DIRS} ${MPG123_INCLUDE_DIR2} )

ENDIF( MPG123_INCLUDE_DIR2 )


#MESSAGE( "MPG123_INCLUDE_DIR1: " ${MPG123_INCLUDE_DIR1} )

#MESSAGE( "MPG123_INCLUDE_DIR2: " ${MPG123_INCLUDE_DIR2} )

#MESSAGE( "MPG123_INCLUDE_DIRS: " ${MPG123_INCLUDE_DIRS} )


FIND_LIBRARY( MPG123_LIBRARIES

  NAMES mpg123 libmpg123.lib

  HINTS

  PATH_SUFFIXES lib64 lib libs64 libs libs/Win32 libs/Win64 Release Debug

  PATHS

  ~/Library/Frameworks

  /Library/Frameworks

  /usr/local

  /usr

  /sw

  /opt/local

  /opt/csw

  /opt

  extern/mpg123/ports/MSVC++/2005

  extern/mpg123/ports/MSVC++/2008

  extern/mpg123/ports/MSVC++/2008clr

  extern/mpg123/ports/MSVC++/2010

)


SET( MPG123_FOUND 0 )

IF( MPG123_LIBRARIES AND MPG123_INCLUDE_DIRS )

  SET( MPG123_FOUND 1 )

  MESSAGE( STATUS "mpg123 found!" )

ELSE( MPG123_LIBRARIES AND MPG123_INCLUDE_DIRS )

  MESSAGE( STATUS "mpg123 not found..." )

ENDIF( MPG123_LIBRARIES AND MPG123_INCLUDE_DIRS )


FIND_PATH(LIBAO_INCLUDE_DIR ao.h /usr/include/ao /usr/local/include/ao)


FIND_LIBRARY(LIBAO_LIBRARIES NAMES ao PATH /usr/lib /usr/local/lib)


IF (LIBAO_INCLUDE_DIR AND LIBAO_LIBRARIES)

  SET(LIBAO_FOUND TRUE)

ENDIF (LIBAO_INCLUDE_DIR AND LIBAO_LIBRARIES)


IF (LIBAO_FOUND)

   IF (NOT LIBAO_FIND_QUIETLY)

      MESSAGE(STATUS "Found libao: ${LIBAO_LIBRARIES}")

   ENDIF (NOT LIBAO_FIND_QUIETLY)

ELSE (LIBAO_FOUND)

   IF (LIBAO_FIND_REQUIRED)

      MESSAGE(FATAL_ERROR "Could not find libao")

   ENDIF (LIBAO_FIND_REQUIRED)

ENDIF (LIBAO_FOUND)


include_directories(${LIBAO_INCLUDE_DIR} ${MPG123_INCLUDE_DIRS})


set(ASSETDIR "${emotime_SOURCE_DIR}/assets" )

set(HEADERDIR "${emotime_SOURCE_DIR}/include" )

set(SRCDIR "${emotime_SOURCE_DIR}/src" )


SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")

add_subdirectory(src)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20151029/b905b0d3/attachment-0001.html>


More information about the CMake mailing list