我有以下情况:
我已经创建了动态库 lib.so。这个库使用了另一个静态库lib.a。它们都使用 Boost 库(我将它们链接到 CMake 文件中)。 (我在Java项目中使用了这个动态库)
这是lib.so中file.cpp的代码,从lib.a调用getFilesFromDirectory()
#include "DrawingDetector.h"
#include "../../DrawingDetection.h"
#include <vector>
#include <boost/filesystem/operations.hpp>
using namespace std;
JNIEXPORT void JNICALL Java_DrawingDetector_detectImage( JNIEnv * env, jobject, jstring jMsg)
{
const char* msg = env->GetStringUTFChars(jMsg,0);
vector<File> filesPic = getFilesFromDirectory(msg,0);
env->ReleaseStringUTFChars(jMsg, msg);
}
这是来自 lib.a 的 getFilesFromDirectory() 的代码:
#include <string.h>
#include <iostream>
#include <boost/filesystem/operations.hpp>
#include "DrawingDetection.h"
using namespace std;
using namespace boost;
using namespace boost::filesystem;
vector<File> getFilesFromDirectory(string dir, int status)
{
vector<File> files;
path directoty = path(dir);
directory_iterator end;
if (!exists(directoty))
{
cout<<"There is no such directory or file!"<<endl;
}
for (directory_iterator itr(directoty); itr != end; ++itr)
{
if ( is_regular_file((*itr).path()))
{
//some code
}
}
return files;
}
但是当我的项目调用 lib.so 库时,它会引发以下消息:
java: symbol lookup error: /home/orlova/workspace/kmsearch/Images/branches/DrawingDetection/jni/bin/lib.so: undefined symbol:_ZN5boost11filesystem34path21wchar_t_codecvt_facetEv
正如我发现的那样,当它试图调用 boost 方法“路径”时,它在 lib.a 中崩溃了。 但我声明了所有 boost header ,并将它们链接到 CMake 文件中。 你能解释一下,为什么它不识别 boost 方法吗?
编辑:
我的编译器 gcc 4.6 的版本。如果我使用 4.5,一切都很好!
此外,如果我直接在 lib.so 的 file.cpp 中使用一些 boost 方法,那么一切正常,例如:
JNIEXPORT void JNICALL Java_DrawingDetector_detectImage( JNIEnv * env, jobject, jstring jMsg)
{
const char* msg = env->GetStringUTFChars(jMsg,0);
path directoty = path("/home/orlova");//if I use boost method here
vector<File> filesPic = getFilesFromDirectory(msg,0);// then everything works fine
env->ReleaseStringUTFChars(jMsg, msg);
}
但是
JNIEXPORT void JNICALL Java_DrawingDetector_detectImage( JNIEnv * env, jobject, jstring jMsg)
{
const char* msg = env->GetStringUTFChars(jMsg,0);
//path directoty = path("/home/orlova");//if I don't use boost method here
vector<File> filesPic = getFilesFromDirectory(msg,0);// then this method causes before-mentioned error!!
env->ReleaseStringUTFChars(jMsg, msg);
你如何解释编译器的这种行为?
请注意,该错误发生在运行时。
已解决
问题出在 CMake 文件中 *target_link_libraries* 中的库顺序。
错误:
find_library( LIBRARY_MAIN
NAMES lib.a
PATHS ../bin
)
set ( LIB_JNI
jpeg
${OpenCV_LIBS}
${BOOST_LIB}
${LIBRARY_MAIN}//static library is the last in the list of libraries and after boost!
)
target_link_libraries( ${PROJECT} ${LIB_JNI} )
右:
find_library( LIBRARY_MAIN
NAMES lib.a
PATHS ../bin
)
set ( LIB_JNI
${LIBRARY_MAIN}
jpeg
${OpenCV_LIBS}
${BOOST_LIB}//boost library is the last in the list and after static library!
)
target_link_libraries( ${PROJECT} ${LIB_JNI} )
最佳答案
您似乎动态链接了 Boost.Filesystem - 如果是这样,您必须确保加载该库。您可以通过将它添加到 Android.mk 中的 LOCAL_LDLIBS 行,或者在加载 lib.so 之前手动预加载它来完成此操作在 Java 代码中。
或者,只需将 Boost(和其他所有内容)静态链接到 lib.so 并忘记所有这些动态困惑。 :)
UPDATE1:关于您发布的更新——尝试将 boost_filesystem.a 作为链接器行中的最后对象。
关于c++ - 无法将 boost 库连接到我的项目 "symbol lookup error",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14360464/
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
如何在buildr项目中使用Ruby?我在很多不同的项目中使用过Ruby、JRuby、Java和Clojure。我目前正在使用我的标准Ruby开发一个模拟应用程序,我想尝试使用Clojure后端(我确实喜欢功能代码)以及JRubygui和测试套件。我还可以看到在未来的不同项目中使用Scala作为后端。我想我要为我的项目尝试一下buildr(http://buildr.apache.org/),但我注意到buildr似乎没有设置为在项目中使用JRuby代码本身!这看起来有点傻,因为该工具旨在统一通用的JVM语言并且是在ruby中构建的。除了将输出的jar包含在一个独特的、仅限ruby
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server
我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e
我正在使用Sequel构建一个愿望list系统。我有一个wishlists和itemstable和一个items_wishlists连接表(该名称是续集选择的名称)。items_wishlists表还有一个用于facebookid的额外列(因此我可以存储opengraph操作),这是一个NOTNULL列。我还有Wishlist和Item具有续集many_to_many关联的模型已建立。Wishlist类也有:selectmany_to_many关联的选项设置为select:[:items.*,:items_wishlists__facebook_action_id].有没有一种方法可以
我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳