在我们的主项目中,构建管理被推迟到CMake。对于我们不同的依赖项,一切都很顺利,包括Boost :: System,但我们无法为Boost :: Serialization编译这个最小的例子。
# Untested with previous versions, yet should work
cmake_minimum_required(VERSION 2.8.11)
project(SerialCmake)
# Boost dependency
set(BOOST_ROOT CACHE PATH "Path to Boost library")
find_package(Boost 1.55 COMPONENTS serialization system)
# Create the target
add_executable(${PROJECT_NAME} main.cpp)
include_directories(${Boost_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME}
${Boost_LIBRARIES})
#include <fstream>
#include <boost/archive/text_oarchive.hpp>
class Serializable
{
friend class boost::serialization::access;
public:
Serializable(int a): a(a)
{}
private:
template <class Archive>
inline void serialize (Archive &ar, const unsigned int version)
{
ar & a;
}
int a;
};
int main(int argc, char **argv)
{
Serializable s1(1);
// Save
{
std::ofstream ofs(argv[1]);
boost::archive::text_oarchive oa(ofs);
oa << s1;
}
return 0;
}
我们的版本:
修改
实际上找到了CMake中列出的两个Boost库(它们在CMake输出中列出)。
首次使用默认参数构建了Boost,第二次按照this post中的说明构建了Boost。这两个版本的错误是相同的。 (实际上,我认为这两个构建都没有问题,因为在非CMake项目中使用库,通过将它们添加到同一帖子中描述的XCode,确实有效。)
我们得到了几个(未定义的符号)链接器错误:
架构x86_64的未定义符号:
“推动::档案:: text_oarchive_impl ::保存(的std :: string const&amp;)“,引自: void boost :: archive :: save_access :: save_primitive(boost :: archive :: text_oarchive&amp;,std :: string const&amp;)in main.o
“推动::档案:: text_oarchive_impl :: text_oarchive_impl(STD :: ostream的和放;, unsigned int)“,引自: main.o中的boost :: archive :: text_oarchive :: text_oarchive(std :: ostream&amp;,unsigned int)
“推动::档案:: basic_text_oprimitive ::〜basic_text_oprimitive()”, 引自: 提高::档案:: text_oarchive_impl ::〜text_oarchive_impl() 在main.o ld:找不到架构x86_64的符号
任何方向?(如您所见,我们要求将应用程序与Boost :: Serialization和Boost :: System相关联。)
答案 0 :(得分:5)
您需要检查find_package
命令实际找到的所有库。最简单的方法
这样做是添加REQUIRED子选项:
find_package(Boost 1.55 REQUIRED system serialization)
对我来说很好。 Xcode 5.0.2,Boost 1.55,CMake 2.8.12.1,OS X 10.9。我正在使用静态库的自定义boost构建(而不是系统)。
恕我直言,无需清除BOOST_ROOT
变量:
set(BOOST_ROOT CACHE PATH "Path to Boost library")
如果已经找到了boost(由其他父项目),你将找到两次工作,如果项目使用自定义提升位置,你将重写它。
答案 1 :(得分:0)
为了它的价值,在将序列化添加回我的一个目标后,我遇到了类似的问题,而且只是cmake没有在CMakeLists.txt中获取更改,因此必须删除缓存:
我只是添加了#34;序列化&#34;到:
#! /usr/bin/env python3
#GeologyDict by Ali M
import sqlite3 as sqlite
import tkinter as tk
from tkinter import Text
from tkinter import Entry
from tkinter import Scrollbar
from tkinter import ttk
#GUI Widgets
class EsperantoDict:
def __init__(self, master):
master.title("EsperantoDict")
master.resizable(False, False)
master.configure(background='#EAFFCD')
self.style = ttk.Style()
self.style.configure("TFrame", background='#EAFFCD')
self.style.configure("TButton", background='#EAFFCD')
self.style.configure("TLabel", background='#EAFFCD')
self.frame_header = ttk.Frame(master, relief=tk.FLAT)
self.frame_header.pack(side=tk.TOP, padx=5, pady=5)
self.logo = tk.PhotoImage(file=r'C:\EsperantoDict\eo.png')
self.small_logo = self.logo.subsample(10, 10)
ttk.Label(self.frame_header, image=self.small_logo).grid(row=0, column=0, stick="ne", padx=5, pady=5, rowspan=2)
ttk.Label(self.frame_header, text='EsperantoDict', font=('Arial', 18, 'bold')).grid(row=0, column=1)
self.frame_content = ttk.Frame(master)
self.frame_content.pack()
self.entry_search = ttk.Entry(self.frame_content)
self.entry_search.grid(row=0, column=0)
self.entry_search.insert(tk.END, "Type to Search")
self.entry_search.bind('<Button-1>', self.entry_delete)
self.button_search = ttk.Button(self.frame_content, text="Search")
self.aks = tk.PhotoImage(file=r'C:\EsperantoDict\search.png')
self.small_aks = self.aks.subsample(3, 3)
self.button_search.config(image=self.small_aks, compound=tk.LEFT)
self.button_search.grid(row=0, column=1, columnspan=2)
self.listbox = tk.Listbox(self.frame_content, height=28)
self.listbox.grid(row=1, column=0)
self.scrollbar = ttk.Scrollbar(self.frame_content, orient=tk.VERTICAL, command=self.listbox.yview)
self.scrollbar.grid(row=1, column=1, sticky='ns')
self.listbox.config(yscrollcommand=self.scrollbar.set)
self.listbox.bind('<<ListboxSelect>>', self.enter_meaning)
self.textbox = tk.Text(self.frame_content, width=60, height=27)
self.textbox.grid(row=1, column=2)
# SQLite
self.db = sqlite.connect(r'C:\EsperantoDict\test.db')
self.cur = self.db.cursor()
self.cur.execute('SELECT Esperanto FROM Words')
for row in self.cur:
self.listbox.insert(tk.END, row)
# SQLite
def enter_meaning(self, tag):
if self.listbox.curselection():
results = self.cur.execute("SELECT English FROM Words")
for row in results:
self.textbox.insert(tk.END, row)
def entry_delete(self, tag):
self.entry_search.delete(0, tk.END)
return None
def main():
root = tk.Tk()
esperantodict = EsperantoDict(root)
root.mainloop()
if __name__ == '__main__': main()
#db table name: Words
##db first field name: Esperanto
##db second field name: English
并出现此错误:
FIND_PACKAGE(Boost REQUIRED COMPONENTS system filesystem date_time serialization)
解决了:
The following Boost libraries could not be found:
boost_serialization