如何修复架构 x86_64 错误?
How to fix architecture x86_64 errors?
我 运行宁 omnet++ 4.6 现在大约 6 个月了。当我尝试在进行一些更改后构建我的项目时:
- 正在从项目中删除头文件
- 正在向我的包含文件夹添加更多文件
我收到这个错误
Creating shared library: ../out/gcc-debug/src/libinet.dylib
Undefined symbols for architecture x86_64:
"BloomFilter::BloomFilter(unsigned long, int, unsigned long, ...)", referenced from:
AODVRouting::AODVRouting() in AODVRouting.o
AODVRouting::AODVRouting() in AODVRouting.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [../out/gcc-debug/src/libinet.dylib] Error 1
make: *** [all] Error 2
我的项目用于构建并且运行在此之前很好。
这是.cc
文件:
#include "BloomFilter.h"
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <cstdarg>
#include <exception>
#include <stdio.h>
#include <string.h>
using namespace std;
#define SETBIT(a, n) (a[n/CHAR_BIT] |= (1<<(n%CHAR_BIT)))
#define GETBIT(a, n) (a[n/CHAR_BIT] & (1<<(n%CHAR_BIT)))
// The Constructor
BloomFilter::BloomFilter(size_t size,int hash_k, size_t nfuncs, ...) {
va_list l;
unsigned int n;
try {
this->a=new char[(size+CHAR_BIT-1)/CHAR_BIT];
}
catch(const std::exception& e)
{
// If we get here is that there is an allocation error .
// We must free the memory .
delete(this);
// std :: cerr << "ERROR: " << e.what () << endl;
// Then raise the exception to indicate that an error occurred.
throw;
}
try {
this->funcs= new hashfunc_t[nfuncs];
}
catch(const std::exception& e){
delete(this->a);
delete(this);
}
va_start(l, nfuncs);
for(n=0; n < nfuncs; ++n) {
this->funcs[n]=va_arg(l, hashfunc_t);
}
va_end(l);
this->nfuncs=nfuncs;
this->asize=size;
this->hash_k=hash_k;
}
// The Destructor
BloomFilter::~BloomFilter() {
/*
delete(this->a);
delete(this->funcs);
delete(this);
*/
}
int BloomFilter::AddToBloom(std::string word){
char t= '1';
int AddFlag; // to know if the element is added successfully
for(int i=0;i<this->hash_k;i++){
AddFlag=Add(word += t);
t++;
}
return AddFlag;
}
int BloomFilter::Add(std::string word){
size_t size = word.size() + 1;
char * buffer = new char[ size ];
strncpy( buffer, word.c_str(), size );
return Add(buffer);
}
int BloomFilter::Add(const char *s)
{
size_t n;
for(n=0; n<this->nfuncs; ++n) {
SETBIT(this->a, this->funcs[n](s)%this->asize);
}
return 0;
}
int BloomFilter::CheckBloom( std::string word){
int CheckFlag;
char t= '1';
for(int i=0;i<this->hash_k;i++){
if(!Check(word += t)) return 0;
t++;
}
return 1;
}
int BloomFilter::Check(std::string word){
size_t size = word.size() + 1;
char * buffer = new char[ size ];
strncpy( buffer, word.c_str(), size );
return Check(buffer);
}
int BloomFilter::Check(const char *s)
{
size_t n;
for(n=0; n< this->nfuncs; ++n) {
if(!(GETBIT(this->a, this->funcs[n](s)%this->asize))) return 0;
}
return 1;
}
//Print information about this object
void BloomFilter::toString(){
/*EV << "[BloomFilter] Hello, I am ready ? " << ready
<<" ; max entry :" << maxEntry << endl;*/
}
此错误的修复方法是什么?
那是链接器错误,不是 C++ 编译器错误。您可能必须将从 .cc 文件生成的 .o 文件添加到链接在一起形成 libinet.dylib
的对象列表中
将文件 .cc
和 .h
从我的根项目复制到我正在处理的项目(在指定目录中)后,我摆脱了这个错误。
我在 运行 omnet++ 和项目浏览器中这样做了。
我不确定 link 如何解决 "linker" 问题,但它确实解决了我的问题。
我 运行宁 omnet++ 4.6 现在大约 6 个月了。当我尝试在进行一些更改后构建我的项目时:
- 正在从项目中删除头文件
- 正在向我的包含文件夹添加更多文件
我收到这个错误
Creating shared library: ../out/gcc-debug/src/libinet.dylib
Undefined symbols for architecture x86_64:
"BloomFilter::BloomFilter(unsigned long, int, unsigned long, ...)", referenced from:
AODVRouting::AODVRouting() in AODVRouting.o
AODVRouting::AODVRouting() in AODVRouting.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [../out/gcc-debug/src/libinet.dylib] Error 1
make: *** [all] Error 2
我的项目用于构建并且运行在此之前很好。
这是.cc
文件:
#include "BloomFilter.h"
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <cstdarg>
#include <exception>
#include <stdio.h>
#include <string.h>
using namespace std;
#define SETBIT(a, n) (a[n/CHAR_BIT] |= (1<<(n%CHAR_BIT)))
#define GETBIT(a, n) (a[n/CHAR_BIT] & (1<<(n%CHAR_BIT)))
// The Constructor
BloomFilter::BloomFilter(size_t size,int hash_k, size_t nfuncs, ...) {
va_list l;
unsigned int n;
try {
this->a=new char[(size+CHAR_BIT-1)/CHAR_BIT];
}
catch(const std::exception& e)
{
// If we get here is that there is an allocation error .
// We must free the memory .
delete(this);
// std :: cerr << "ERROR: " << e.what () << endl;
// Then raise the exception to indicate that an error occurred.
throw;
}
try {
this->funcs= new hashfunc_t[nfuncs];
}
catch(const std::exception& e){
delete(this->a);
delete(this);
}
va_start(l, nfuncs);
for(n=0; n < nfuncs; ++n) {
this->funcs[n]=va_arg(l, hashfunc_t);
}
va_end(l);
this->nfuncs=nfuncs;
this->asize=size;
this->hash_k=hash_k;
}
// The Destructor
BloomFilter::~BloomFilter() {
/*
delete(this->a);
delete(this->funcs);
delete(this);
*/
}
int BloomFilter::AddToBloom(std::string word){
char t= '1';
int AddFlag; // to know if the element is added successfully
for(int i=0;i<this->hash_k;i++){
AddFlag=Add(word += t);
t++;
}
return AddFlag;
}
int BloomFilter::Add(std::string word){
size_t size = word.size() + 1;
char * buffer = new char[ size ];
strncpy( buffer, word.c_str(), size );
return Add(buffer);
}
int BloomFilter::Add(const char *s)
{
size_t n;
for(n=0; n<this->nfuncs; ++n) {
SETBIT(this->a, this->funcs[n](s)%this->asize);
}
return 0;
}
int BloomFilter::CheckBloom( std::string word){
int CheckFlag;
char t= '1';
for(int i=0;i<this->hash_k;i++){
if(!Check(word += t)) return 0;
t++;
}
return 1;
}
int BloomFilter::Check(std::string word){
size_t size = word.size() + 1;
char * buffer = new char[ size ];
strncpy( buffer, word.c_str(), size );
return Check(buffer);
}
int BloomFilter::Check(const char *s)
{
size_t n;
for(n=0; n< this->nfuncs; ++n) {
if(!(GETBIT(this->a, this->funcs[n](s)%this->asize))) return 0;
}
return 1;
}
//Print information about this object
void BloomFilter::toString(){
/*EV << "[BloomFilter] Hello, I am ready ? " << ready
<<" ; max entry :" << maxEntry << endl;*/
}
此错误的修复方法是什么?
那是链接器错误,不是 C++ 编译器错误。您可能必须将从 .cc 文件生成的 .o 文件添加到链接在一起形成 libinet.dylib
的对象列表中将文件 .cc
和 .h
从我的根项目复制到我正在处理的项目(在指定目录中)后,我摆脱了这个错误。
我在 运行 omnet++ 和项目浏览器中这样做了。
我不确定 link 如何解决 "linker" 问题,但它确实解决了我的问题。