Ask Your Question
1

Example of makefile

asked 2013-06-04 03:08:32 -0600

asqz gravatar image

Hi,

I am trying to create a makefile for a program which use openCV, but I can't create one. One thing that could help me is an example of a makefile you are using which you know work, so that I could take as a reference for writing my own makefile. Could you publish one please ? I am using ubuntu 12.04

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted
1

answered 2013-06-04 03:22:18 -0600

Guanta gravatar image

This is my typical CMakeLists.txt for testing code, which also includes several commented lines for Qt and OpenMP, which you can uncomment if needed. Since this is a CMakeLists.txt you need cmake to create the actual Makefile, e.g. via "ccmake ." (where '.' refers to the current location).

project(Test)
cmake_minimum_required(VERSION 2.8)

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")

include_directories(${CMAKE_CURRENT_SOURCE_DIR})

#if you want to have Qt4-support uncomment this
#find_package(Qt4 REQUIRED)
#if(QT_FOUND)
## activate XML component
#set(QT_USE_QTXML TRUE)
#include(${QT_USE_FILE})
#add_definitions(${QT_DEFINITIONS})
#include_directories(${CMAKE_CURRENT_BINARY_DIR} ${QT_INCLUDE_DIR})
#endif(QT_FOUND)    

find_package( OpenCV REQUIRED )
if( OpenCV_FOUND )
list( APPEND ThirdParty_LIBS ${OpenCV_LIBS} )
    include_directories( ${OpenCV_INCLUDE_DIRS} )
endif( OpenCV_FOUND )

# uncomment this for OpenMP support
#FIND_PACKAGE(OpenMP REQUIRED)  
#if(OPENMP_FOUND)
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
#endif()

# uncomment this for c++11 support
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(${PROJECT_NAME}_SRC main.cpp test1.cpp test2.cpp)
set(${PROJECT_NAME}_HDR test1.h test2.h)
# currently we don't have any forms-uncomment if you have qt-forms
#set(${PROJECT_NAME}_FORMS mainwindow.ui)

# also no moc from headers needed (uncomment if qt used)
#QT4_WRAP_CPP(${PROJECT_NAME}_HDR_MOC ${${PROJECT_NAME}_HDR})
# no forms
#QT4_WRAP_UI(${PROJECT_NAME}_FORMS_HDR ${${PROJECT_NAME}_FORMS})

# use this line if you have used Qt instead the next line
#add_executable(${PROJECT_NAME} ${${PROJECT_NAME}_SRC} ${${PROJECT_NAME}_HDR_MOC} ${${PROJECT_NAME}_FORMS_HDR} )
add_executable(${PROJECT_NAME} ${${PROJECT_NAME}_SRC} ${${PROJECT_NAME}_HDR})
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})
edit flag offensive delete link more
1

answered 2013-06-04 15:40:00 -0600

Guanta gravatar image

I have found another old Makefile, which I used with an old OpenCV-version. However, I don't know if OpenCV's pkg-files have been fixed again.

CC=g++
#CFLAGS+=-g
CFLAGS+=`pkg-config --cflags opencv`
LDFLAGS+=`pkg-config --libs opencv`

PROG=opencvtest
OBJS=$(PROG).o

.PHONY: all clean
$(PROG): $(OBJS)
    $(CC) -o $(PROG) $(OBJS) $(LDFLAGS)

%.o: %.cpp
    $(CC) -c $(CFLAGS) $<

all: $(PROG)

clean:
    rm -f $(OBJS) $(PROG)

Here the correct flags (i.e. -I -L ) are handled by pkgconfig, i.e. also that you need to set the PKG_CONFIG_PATH to the folder which contains the opencv.pc-file.

edit flag offensive delete link more
0

answered 2013-06-07 04:00:58 -0600

asqz gravatar image

updated 2013-06-07 04:03:00 -0600

Thanks for all your answers, but I am not using CMake. Here is the makefile I created :


########LIBRAIRIES

LIBS_ffmpeg = -lm -lz -lpthread -lavformat -lavcodec -lavutil

LIBS_opencv = -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_video -lopencv_objdetect

LIBS_autres = -lpthread -ldl -lm

LIBS = $(LIBS_autres) $(LIBS_ffmpeg) $(LIBS_opencv)

########CONSTANTES

CXXFLAGS = -O2 -g -Wall -fmessage-length=0 -D__STDC_CONSTANT_MACROS OBJS = test.o FluxVideo.o TARGET = test

########REGLES

$(TARGET): $(OBJS) $(CXX) -o $(TARGET) $(OBJS) $(LIBS)

%.o: %.cpp $(CXX) -o $@ -c $< $(CXXFLAGS) $(LIBS)

all: $(TARGET)

clean: rm -f $(OBJS) $(TARGET)

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-06-04 03:08:32 -0600

Seen: 30,911 times

Last updated: Jun 07 '13