I have installed boost on my Ubunutu machine using following command:
sudo apt-get install libboost-all-dev
When I try to compile my C++ program using: g++ *.cpp -o main
I get the following error message:
/tmp/ccnMHibM.o: In function
main': main.cpp:(.text+0x46): undefined reference to
boost::thread::thread()' /tmp/ccnMHibM.o: In function__static_initialization_and_destruction_0(int, int)': main.cpp:(.text+0xec): undefined reference to
boost::system::generic_category()' main.cpp:(.text+0xf8): undefined reference toboost::system::generic_category()' main.cpp:(.text+0x104): undefined reference to
boost::system::system_category()' /tmp/ccnMHibM.o: In functionboost::system::error_category::std_category::equivalent(int, std::error_condition const&) const': main.cpp:(.text._ZNK5boost6system14error_category12std_category10equivalentEiRKSt15error_condition[_ZNK5boost6system14error_category12std_category10equivalentEiRKSt15error_condition]+0xb8): undefined reference to
boost::system::generic_category()' main.cpp:(.text._ZNK5boost6system14error_category12std_category10equivalentEiRKSt15error_condition[_ZNK5boost6system14error_category12std_category10equivalentEiRKSt15error_condition]+0xf3): undefined reference toboost::system::generic_category()' /tmp/ccnMHibM.o: In function
boost::system::error_category::std_category::equivalent(std::error_code const&, int) const': main.cpp:(.text._ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei[_ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei]+0xb8): undefined reference toboost::system::generic_category()' main.cpp:(.text._ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei[_ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei]+0xf3): undefined reference to
boost::system::generic_category()' main.cpp:(.text._ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei[_ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei]+0x1d2): undefined reference toboost::system::generic_category()' /tmp/ccnMHibM.o: In function
boost::thread::~thread()': main.cpp:(.text._ZN5boost6threadD2Ev[_ZN5boost6threadD5Ev]+0x14): undefined reference toboost::thread::detach()' /tmp/cc70LCDt.o: In function
__static_initialization_and_destruction_0(int, int)': ts_hash_table.cpp:(.text+0x819): undefined reference toboost::system::generic_category()' ts_hash_table.cpp:(.text+0x825): undefined reference to
boost::system::generic_category()' ts_hash_table.cpp:(.text+0x831): undefined reference to `boost::system::system_category()' collect2: error: ld returned 1 exit status
When I try to manually specify the path to boost library, like so: g++ *.cpp -o main -lboost_thread
I get another error:
/usr/bin/ld: /tmp/ccyqvpMZ.o: undefined reference to symbol '_ZN5boost6system15system_categoryEv' //usr/lib/x86_64-linux-gnu/libboost_system.so.1.65.1: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status
Here is my actual code (main.cpp
):
#include "ts_hash_table.hpp"
HASH_TABLE* hash_table = createHashTable(TABLE_SIZE);
int main() {
srand (time(NULL));
boost::thread arr[THREAD_NUM];
return 0;
}
And here is ts_hash_table.hpp
file:
#ifndef TS_HASH_TABLE_H
#define TS_HASH_TABLE_H
#include <iostream>
#include <boost/thread/thread.hpp>
#include <atomic>
#include <stdio.h>
#include <stdlib.h>
#define TABLE_SIZE 10
#define THREAD_NUM 10
typedef struct element{
std::atomic<int> tag;
std::atomic<int> data;
std::atomic<int> key;
struct element* next;
}ELEMENT;
typedef struct {
int size;
std::atomic<ELEMENT*>* buckets;
}HASH_TABLE;
extern HASH_TABLE* hash_table;
HASH_TABLE* createHashTable(int);
ELEMENT* createElement(int,int);
ELEMENT* get(int);
int calculateHash(int);
void insert(int, int, int);
void modify(int, int);
void printList(ELEMENT*);
void printTable();
void clearList(ELEMENT**);
void clearTable();
#endif // TS_HASH_TABLE_H
Can anyone help me out and tell me what I am doing wrong?
Aucun commentaire:
Enregistrer un commentaire