對不起,我的英語。我創建了一個共享庫,我的程序動態加載了它。 它工作正常,但問題是我將一個指針傳遞給共享庫,但是這不能訪問指針內存。另一方面,沒有問題。共享庫無法訪問程序的內存
關於如何解決這個問題的任何想法?
注:我使用Linux,但如果這個想法適用於其他操作系統,我會尋找這相當於
下面的代碼:
unsigned analizer::analizeText() {
std::cout << "thread started" << std::endl;
while(true)
{
pause.lock();
varMu.lock();
unsigned enable = __enable;
unsigned line = __line;
unsigned _colum = __colum;
unsigned offset = __offset;
varMu.unlock();
unsigned begin = offset;
std::cout << "get usafed docs" << std::endl;
std::cout << doc->getText() << std::endl;//the program crash
vector<document*> doc = _openDocuments->getUnsavedDocs(_openDocuments->traductDoc(this->doc)); std::cout << "relized" << std::endl;
while (beginElements.find(_openDocuments->getChar(begin-l)) == beginElements.end() and begin > 0)
--begin;
word = this->doc->getText().substr(begin,_offset-begin);
delete UunFile;
加載庫:
#include <iostream>
pBear::language *_language;
using namespace pBear;
void language::load()
{
boost::filesystem::directory_iterator end;
for (boost::filesystem::directory_iterator it(languagePath); it != end; ++it)
{
void *hndl = dlopen(it->path().c_str(), RTLD_NOW);
if(hndl == NULL)
{
std::cerr « dlerror() « std::endl;
exit(-1);
}
std::function<LanguageDatas*(pBear::openDocuments*)> fun = (LanguageDatas*(*)(pBear::openDocuments*)) dlsym(hndl, "colorMaker");
LanguageDatas *dat = fun(openDocuments);
dataLanguages[dat->getName()] = dat;
}
}
通指針:
ana = _language->getLanguage(doc->getProyect()->getLanguage())->getAnalizer(doc);
最後程序的消息:
analize
線程開始
得到usafed文檔
分割故障(核心轉儲)
代碼照片 - 非常糟糕的主意,請將您的代碼作爲文本粘貼 – duDE 2014-09-04 14:29:28
也會添加錯誤消息。 – Basilevs 2014-09-04 14:56:46
好的,我添加了程序的最後一條消息 – 2014-09-04 15:46:04