1

外部の静的ライブラリにコンパイルしようとしているクラスがいくつかあります。私のlinked_list.hpp(コンパイルしようとしているlinked_listのヘッダー)は次のようになります。

#include "list_base.hpp"

template <typename T>

class Linked_list : public List_base <T> {


    public://
        Linked_list();
        ~Linked_list();

    public://accessor functions
        Linked_list<T> * next();//go to the next element in the list
        Node<T> * get_current_node() const;//return the current node
        T get_current() const;//get the current data
        T get(int index) const;//this will get the specified index and will return the data it holds

    public://worker functions
        Linked_list<T> * push(T value);//push a value into the front of the list
        Linked_list<T> * pop_current();//deletes the current_node--resets the current as the next element in the list!
        Linked_list<T> * reset();//this resets the current to the front of the list
        Linked_list<T> * erase(int index);

    private://variables
        Node<T> * current;//store the current node


};

#include "linked_list.cpp"//grab the template implementation file


#endif

私のコードヘッダーはすべて「header」ディレクトリにあり、実装は私が持っている実装フォルダにあります。これらは-Iディレクトリとして渡されます。

コンパイル用のmakefileコマンドは次のようになります。

static: $(DEPENDENCIES)
    ar rcs liblist_templates.a node.o list_base.o linked_list.o 

実行すると、このエラーが発生します...

/usr/bin/ranlib: warning for library: liblist_templates.a the table of contents is empty (no object file members in the library define global symbols)

「linked_list.hpp」とライブラリの他のいくつかの部分を含むマスターヘッダーファイルを作成しましたが、それをインクルードするたびに、インクルードされているcppファイルを探しているようです。私はこれで何が間違っていますか?このコードから既存のプロジェクトにドロップできるポータブルライブラリを作成したいと思います。

4

1 に答える 1

2

If your library only contains template code, it can not be compiled in itself: for example, the compiler does not know which type will be used as T in the linked list.

When you compiled linked_list.cpp, the compiler only realized basic syntax checks and generated an empty object file. ranlib is then complaining since you ask him to create an empty library out of all these empty object files.

The solution is simple: do nothing! Your client code only needs the source files; it doesn't need to be linked against any library. And you'll always need to ship the .cpp files, since the compiler can not do anything without them.

于 2012-12-01T23:07:48.353 に答える