I'm having trouble trying to link a library that I recently pushed onto Git to my CMake project.
I have named the library octal (GitHub) and am trying to link it to my other library bulletframe (GitHub). Both projects are created by me.
I anticipated that linking the library wouldn't work the first time, so I only started off with a couple of source files in octal. The folder structure of octal is as follows:
.gitignore
CMakeLists.txt
.git/
build/ # generated project files go here, but right now it's empty
src/
CMakeLists.txt
octal.h # this is empty
octal/
vector/
vector.h
vector.cpp
octal/CMakeLists.txt
#...
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_HOME_DIRECTORY}")
add_subdirectory("src")
octal/src/CMakeLists.txt
macro(add_include)
set(ALL_INCLUDES ${ALL_INCLUDES} ${ARGV})
endmacro(add_include)
add_include("octal.h")
add_include("octal/vector/vector.cpp" "octal/vector/vector.h")
add_library(${PROJECT_NAME} STATIC ${ALL_INCLUDES})
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY})
octal/src/vector/vector.h
#pragma once
namespace octal
{
class Vector
{
// ...
Vector Add(Vector other);
Vector Subtract(Vector other);
Vector Multiply(Vector other);
Vector Multiply(double x);
Vector Divide(Vector other);
Vector Divide(double x);
// ...
}
}
These configurations are successful in building a liboctal.a file, however I'm not sure if they are linked with bulletframe correctly. There are multiple files that use classes from octal, but this is the first error that it gives after it tries to compile the first source file, entity.cpp:
fatal error: octal/vector/vector.h: No such file or directory
#include "octal/vector/vector.h"
^
compilation terminated.
bulletframe has a similar folder structure to octal
bulletframe/CMakeLists.txt:
include(ExternalProject)
set(EXPROJ_DIR "${CMAKE_HOME_DIRECTORY}/external")
set(LIB_DIR "${CMAKE_HOME_DIRECTORY}/lib")
set(OCTAL_NAME "octal-git")
set(OCTAL_GIT "http://ift.tt/1M8U1mY")
set(OCTAL_PREFIX "${EXPROJ_DIR}/${OCTAL_NAME}")
set(OCTAL_SOURCE_DIR "${EXPROJ_DIR}/${OCTAL_NAME}")
set(OCTAL_BUILD_DIR "${EXPROJ_DIR}/${OCTAL_NAME}/build")
set(OCTAL_INSTALL_DIR "${LIB_DIR}")
ExternalProject_Add(${OCTAL_NAME}
PREFIX ${OCTAL_PREFIX}
TMP_DIR ${OCTAL_PREFIX}-tmp
STAMP_DIR ${OCTAL_PREFIX}-stamp
# - Download Step ------------------
GIT_REPOSITORY ${OCTAL_GIT}
# - Update Step --------------------
UPDATE_COMMAND ""
# - Configure Step -----------------
SOURCE_DIR ${OCTAL_SOURCE_DIR}
# - Build Step ---------------------
BINARY_DIR ${OCTAL_BUILD_DIR}
# - Install Step ------------------
INSTALL_COMMAND ""
CMAKE_ARGS
"-DCMAKE_BUILD_TYPE=Release"
)
add_subdirectory(src)
bulletframe/src/CMakeLists.txt
macro(add_include)
set(ALL_INCLUDES ${ALL_INCLUDES} ${ARGV})
endmacro(add_include)
add_include("entity.cpp")
add_library(${PROJECT_NAME} STATIC ${ALL_INCLUDES})
target_link_libraries(${PROJECT_NAME} ${OCTAL_NAME})
As it stands, my current configurations are unable to build bulletframe with both the Visual Studio 10 2013 and MinGW Makefiles generators.
A couple concerns come to mind as I witnessed the compiler giving similar errors every time:
- Am I not building the static library (
octal) correctly? - Am I not linking it to my project (
bulletframe) correctly?
Aucun commentaire:
Enregistrer un commentaire