2016-07-07 5 views
0

のためのマクロをインストールし、この私のプロジェクト構造:作成cmakeのライブラリ

main 
| 
--src 
    | 
    --feed.h 
    --feed.cc 
    --other files 
    --CMakeLists2.txt 
--test 
    | 
    --test.cpp 
    --CMakeLists3.txt 
CMakeLists1.txt 

CMakeLists1.txt

cmake_minimum_required (VERSION 2.8.11) 
project (Feedparser) 

set(CMAKE_MODULE_PATH cmake) 

find_package(PTHREAD REQUIRED) 
find_package(CURL REQUIRED) 

include(CheckCXXCompilerFlag) 
CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX11) 
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X) 
if(COMPILER_SUPPORTS_CXX11) 
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 ") 
elseif(COMPILER_SUPPORTS_CXX0X) 
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x ") 
else() 
     message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") 
endif() 

add_subdirectory (src) 

add_subdirectory (test) 

CMakeLists2.txt

cmake_minimum_required (VERSION 2.8.11) 

add_library (Feedparser news.h xml2json.hpp jsonxx.cc curler.cc feed.cc) 

target_link_libraries(Feedparser pthread) 
target_link_libraries(Feedparser curl) 

install(TARGETS Feedparser 
     RUNTIME DESTINATION bin 
     LIBRARY DESTINATION lib 
     ARCHIVE DESTINATION /usr/lib) 
install(FILES "feed.h" DESTINATION /usr/include ) 
target_include_directories (Feedparser PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) 

CMakeLists3.txt

cmake_minimum_required (VERSION 2.8.11) 

add_executable(Feedtest test.cc) 

target_link_libraries (Feedtest LINK_PUBLIC Feedparser) 

ここに私のヘッダーファイルがあります。

#include "news.h" 
#include "curler.cc" 
#include "jsonxx.h" 
#include "jsonxx.cc" 
#include <iostream> 
#include <sstream> 
#include <stdlib.h> 
#include <thread> 
#include <stdio.h> 
using namespace std; 
using namespace jsonxx; 

class feed{ 

    map <string,string> info; 
    std::map<int, Object> items; 
    string url; 
    news News; 
    Object *item; 
    void strip_items(); 
    public: 
     Object json; 

     feed(string url); 

     void create(string url){ 
      this->url = url; 
     } 
     feed(){} 
     string get_topic(){ 
      return info["title"]; 
     } 
     bool fetch(); 
     bool fetch_data(); 
     bool parse(); 
     string get_url(){ 
      return url; 
     } 
     string get_item_title(int index){ 
      return News.title[index]; 
     } 

     string get_item_img(int index){ 
      return News.image[index]; 
     } 

     string get_item_link(int index){ 
      return News.link[index]; 
     } 

     int get_total(){ 
      return News.num_item; 
     } 

     struct news get_news(){ 
      return News; 
     } 



}; 

feed.h

私はfeed.ccでfeed.hを含めると、コンパイルとどのようにコンパイラが直接アーカイブに.CXXファイルと.hファイルをリンクするんでしょうか?

このライブラリをインストールするには、どのようにcmakeスクリプトを記述しますか? 私のミスはどこですか?

答えて

0

C++の構築プロセスは、2つの段階からなる:

コンパイル:コンパイラはintermidiateバイナリを生成し、すべてのソース(.cc)ファイル上で動作します。

リンク:リンカは、すべての中間バイナリで実行され、宣言と定義が一致します。 最後に、最終的なバイナリを作成するためにそれらのすべてを結合します。


これを念頭において、コンパイラがわからないことに遭遇していないことを確認する必要があります。そのため、ヘッダー(.h)を含めるのです。

リンカーには、コンパイラーが作成するすべてのものを入力する必要があります。

+0

アーカイブについても同じですか? .hファイルを.ccファイルに含めるべきですか?それとも外部でコンパイルするのですか? .hファイルと.aファイルをそれぞれ/ usr/includeと/ usr/lib /に移動するために、cmakeファイルにどのような変更を加える必要がありますか? @IvanRubinson –

関連する問題