I have created a project with intention of using hunspell functions in it. I am working in Ubuntu. I installed and compiled hunspell library and linked it with g++ -o wc.exe -lhunspell-1.6 wordcheck.cxx and everything seemed ok. But when I tried to compile and launch my project I got some errors.
#include <iostream>
#include "hunspell/hunspell.hxx"
using namespace std;
int main(int argc,char** argv)
{
FILE* lst=fopen("wordlist.txt","r");
if(!lst)
{
cerr<<"Can not open file\n";
return 1;
}
Hunspell* hs=new Hunspell(argv[1],argv[2]);
delete hs;
return 0;
}
and the errors were:
/home/alex2/Документы/bO/wordcheck.cxx:14: undefined reference to Hunspell::Hunspell(char const*, char const*, char const*)'
/home/alex2/Документы/bO/wordcheck.cxx:15: undefined reference toHunspell::~Hunspell()'
collect2: error: ld returned 1 exit status
atus
I have no idea what is wrong. I tried using
Hunspell* hs=new Hunspell();
and got that there is a candidate for it that requires three parameters:
/usr/local/include/hunspell/hunspell.hxx:115:3: note: candidate: Hunspell::Hunspell(const char*, const char*, const char*)
Hunspell(const char* affpath, const char* dpath, const char* key = NULL);
The only difference is char const* and const char* but I always thought it is the same thing. The entire project is similar to the example file hunspell provides and I have no idea what am I doing wrong and why my thing is not working.
Related
I am facing the following problem, I am trying to convert an std::string object into an std::basic_string<char8_t> one, using the codecvt library. The code is the following:
#include <string>
#include <codecvt>
#include <locale>
int main()
{
std::string str = "Test string";
std::wstring_convert <std::codecvt_utf8_utf16 <char8_t>, char8_t> converter_8_t;
converter_8_t.from_bytes( str );
}
The problem is that when I try to compile it with g++ -std=c++20 (g++ 11.2.0) I got the following error:
/usr/bin/ld: /tmp/cck8g9Wa.o: in function `std::__cxx11::wstring_convert<std::codecvt_utf8_utf16<char8_t, 1114111ul, (std::codecvt_mode)0>, char8_t, std::allocator<char8_t>, std::allocator<char> >::wstring_convert()':
other.cpp:(.text._ZNSt7__cxx1115wstring_convertISt18codecvt_utf8_utf16IDuLm1114111ELSt12codecvt_mode0EEDuSaIDuESaIcEEC2Ev[_ZNSt7__cxx1115wstring_convertISt18codecvt_utf8_utf16IDuLm1114111ELSt12codecvt_mode0EEDuSaIDuESaIcEEC5Ev]+0x2c): undefined reference to `std::codecvt_utf8_utf16<char8_t, 1114111ul, (std::codecvt_mode)0>::codecvt_utf8_utf16(unsigned long)'
collect2: error: ld returned 1 exit status
Do you know what could be the problem? Am I trying to convert the std::string object in the wrong way? Thanks.
C++ keywords: char8_t (since C++20)
As far as I understand char8_t is of char type as is your std::string. A simple cast should work.
Iam learning boost and test some examples, so I link boost libraries in my QT project with MinGW compiler, and I want to link all the libraries so i can use anything from filesystem to asio and go with different examples that use many classes.
this my .pro file which I link the boost libraries
INCLUDEPATH += C:/boost_1_66_0
LIBS += -LC:/boost_1_66_0/stage/lib -llibboost_atomic-mgw63-mt-d-x32-1_66\
-llibboost_atomic-mgw63-mt-x32-1_66\
-llibboost_chrono-mgw63-mt-d-x32-1_66\
-llibboost_chrono-mgw63-mt-x32-1_66\
-llibboost_container-mgw63-mt-d-x32-1_66\
-llibboost_container-mgw63-mt-x32-1_66\
-llibboost_context-mgw63-mt-d-x32-1_66\
-llibboost_context-mgw63-mt-x32-1_66\
-llibboost_coroutine-mgw63-mt-d-x32-1_66\
-llibboost_coroutine-mgw63-mt-x32-1_66\
-llibboost_date_time-mgw63-mt-d-x32-1_66\
-llibboost_date_time-mgw63-mt-x32-1_66\
-llibboost_exception-mgw63-mt-d-x32-1_66\
-llibboost_exception-mgw63-mt-x32-1_66\
-llibboost_filesystem-mgw63-mt-d-x32-1_66\
-llibboost_filesystem-mgw63-mt-x32-1_66\
-llibboost_graph-mgw63-mt-d-x32-1_66\
-llibboost_graph-mgw63-mt-x32-1_66\
-llibboost_iostreams-mgw63-mt-d-x32-1_66\
-llibboost_iostreams-mgw63-mt-x32-1_66\
-llibboost_locale-mgw63-mt-d-x32-1_66\
-llibboost_locale-mgw63-mt-x32-1_66\
-llibboost_log-mgw63-mt-d-x32-1_66\
-llibboost_log-mgw63-mt-x32-1_66\
-llibboost_log_setup-mgw63-mt-d-x32-1_66\
-llibboost_log_setup-mgw63-mt-x32-1_66\
-llibboost_math_c99-mgw63-mt-d-x32-1_66\
-llibboost_math_c99-mgw63-mt-x32-1_66\
-llibboost_math_c99f-mgw63-mt-d-x32-1_66\
-llibboost_math_c99f-mgw63-mt-x32-1_66\
-llibboost_math_c99l-mgw63-mt-d-x32-1_66\
-llibboost_math_c99l-mgw63-mt-x32-1_66\
-llibboost_math_tr1-mgw63-mt-d-x32-1_66\
-llibboost_math_tr1-mgw63-mt-x32-1_66\
-llibboost_math_tr1f-mgw63-mt-d-x32-1_66\
-llibboost_math_tr1f-mgw63-mt-x32-1_66\
-llibboost_math_tr1l-mgw63-mt-d-x32-1_66\
-llibboost_math_tr1l-mgw63-mt-x32-1_66\
-llibboost_prg_exec_monitor-mgw63-mt-d-x32-1_66\
-llibboost_prg_exec_monitor-mgw63-mt-x32-1_66\
-llibboost_program_options-mgw63-mt-d-x32-1_66\
-llibboost_program_options-mgw63-mt-x32-1_66\
-llibboost_random-mgw63-mt-d-x32-1_66\
-llibboost_random-mgw63-mt-x32-1_66\
-llibboost_regex-mgw63-mt-d-x32-1_66\
-llibboost_regex-mgw63-mt-x32-1_66\
-llibboost_serialization-mgw63-mt-d-x32-1_66\
-llibboost_serialization-mgw63-mt-x32-1_66\
-llibboost_signals-mgw63-mt-d-x32-1_66\
-llibboost_signals-mgw63-mt-x32-1_66\
-llibboost_stacktrace_basic-mgw63-mt-d-x32-1_66\
-llibboost_stacktrace_basic-mgw63-mt-x32-1_66\
-llibboost_stacktrace_noop-mgw63-mt-d-x32-1_66\
-llibboost_stacktrace_noop-mgw63-mt-x32-1_66\
-llibboost_system-mgw63-mt-d-x32-1_66\
-llibboost_system-mgw63-mt-x32-1_66\
-llibboost_test_exec_monitor-mgw63-mt-d-x32-1_66\
-llibboost_test_exec_monitor-mgw63-mt-x32-1_66\
-llibboost_thread-mgw63-mt-d-x32-1_66\
-llibboost_thread-mgw63-mt-x32-1_66\
-llibboost_timer-mgw63-mt-d-x32-1_66\
-llibboost_timer-mgw63-mt-x32-1_66\
-llibboost_type_erasure-mgw63-mt-d-x32-1_66\
-llibboost_type_erasure-mgw63-mt-x32-1_66\
-llibboost_unit_test_framework-mgw63-mt-d-x32-1_66\
-llibboost_unit_test_framework-mgw63-mt-x32-1_66\
-llibboost_wave-mgw63-mt-d-x32-1_66\
-llibboost_wave-mgw63-mt-x32-1_66\
-llibboost_wserialization-mgw63-mt-d-x32-1_66\
-llibboost_wserialization-mgw63-mt-x32-1_66\
I go to the boost lib folder and add all the libraries as above, I start now testing some functions and I still got undefine refernce to some functions although I linked all the libararies and I use it in Release mode here is my main in which i use boost archive
#include <fstream>
#include <ios>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <locale>
#include <codecvt>
#include <cstring>
#include <boost/archive/text_oarchive.hpp>
using namespace boost::archive;
using namespace std;
int main(int argc, char *argv[])
{
ofstream out("D:/a.txt");
text_oarchive oa(out);
int a = INT_MAX;
oa << a;
out.close();
return 0;
}
this is the error I got
release/main.o:main.cpp:(.text.startup+0xf1): undefined reference to `boost::archive::archive_exception::archive_exception(boost::archive::archive_exception::_exception_code, char const*, char const*)'
release/main.o:main.cpp:(.text$_ZN5boost7archive6detail15common_oarchiveINS0_13text_oarchiveEE5vsaveENS0_14object_id_typeE[__ZN5boost7archive6detail15common_oarchiveINS0_13text_oarchiveEE5vsaveENS0_14object_id_typeE]+0x69): undefined reference to `boost::archive::archive_exception::archive_exception(boost::archive::archive_exception::_exception_code, char const*, char const*)'
release/main.o:main.cpp:(.text$_ZN5boost7archive6detail15common_oarchiveINS0_13text_oarchiveEE5vsaveENS0_21object_reference_typeE[__ZN5boost7archive6detail15common_oarchiveINS0_13text_oarchiveEE5vsaveENS0_21object_reference_typeE]+0x62): undefined reference to `boost::archive::archive_exception::archive_exception(boost::archive::archive_exception::_exception_code, char const*, char const*)'
release/main.o:main.cpp:(.text$_ZN5boost7archive6detail15common_oarchiveINS0_13text_oarchiveEE5vsaveENS0_13class_id_typeE[__ZN5boost7archive6detail15common_oarchiveINS0_13text_oarchiveEE5vsaveENS0_13class_id_typeE]+0x63): undefined reference to `boost::archive::archive_exception::archive_exception(boost::archive::archive_exception::_exception_code, char const*, char const*)'
release/main.o:main.cpp:(.text$_ZN5boost7archive6detail15common_oarchiveINS0_13text_oarchiveEE5vsaveENS0_23class_id_reference_typeE[__ZN5boost7archive6detail15common_oarchiveINS0_13text_oarchiveEE5vsaveENS0_23class_id_reference_typeE]+0x63): undefined reference to `boost::archive::archive_exception::archive_exception(boost::archive::archive_exception::_exception_code, char const*, char const*)'
release/main.o:main.cpp:(.text$_ZN5boost7archive6detail15common_oarchiveINS0_13text_oarchiveEE5vsaveENS0_13tracking_typeE[__ZN5boost7archive6detail15common_oarchiveINS0_13text_oarchiveEE5vsaveENS0_13tracking_typeE]+0x63): more undefined references to `boost::archive::archive_exception::archive_exception(boost::archive::archive_exception::_exception_code, char const*, char const*)' follow
collect2.exe: error: ld returned 1 exit status
mingw32-make[1]: *** [Makefile.Release:63: release/Normal2.exe] Error 1
mingw32-make: *** [Makefile:36: release] Error 2
mingw32-make[1]: Leaving directory 'D:/WorkPlace/CppProject/cpp/build-Normal2-Desktop_QT_5_12_0_MinGW_32_bit-Release'
17:41:30: The process "C:\Qt\Qt5.12.0\Tools\mingw730_32\bin\mingw32-make.exe" exited with code 2.
Error while building/deploying project Normal2 (kit: Desktop QT 5.12.0 MinGW 32-bit)
When executing step "Make"
17:41:30: Elapsed time: 00:04.
so what mistake i made to give me those erros, and I already linked all the libraries and add them to my Project i did not test more examples yet so i don't know if I will got some errors more if i used different classes.
Iam using this website to learn more about boost library here so I am going with different examples to test and I need to link all boost libraries
Update
This now my .pro file i removed the lib at the beggining and I remove debug libraries and use only release here is my .pro file
LIBS += -LC:/boost_1_66_0/stage/lib -lboost_atomic-mgw63-mt-x32-1_66\
-lboost_chrono-mgw63-mt-x32-1_66\
-lboost_container-mgw63-mt-x32-1_66\
-lboost_context-mgw63-mt-x32-1_66\
-lboost_coroutine-mgw63-mt-x32-1_66\
-lboost_date_time-mgw63-mt-x32-1_66\
-lboost_exception-mgw63-mt-x32-1_66\
-lboost_filesystem-mgw63-mt-x32-1_66\
-lboost_graph-mgw63-mt-x32-1_66\
-lboost_iostreams-mgw63-mt-x32-1_66\
-lboost_locale-mgw63-mt-x32-1_66\
-lboost_log-mgw63-mt-x32-1_66\
-lboost_log_setup-mgw63-mt-x32-1_66\
-lboost_math_c99-mgw63-mt-x32-1_66\
-lboost_math_c99f-mgw63-mt-x32-1_66\
-lboost_math_c99l-mgw63-mt-x32-1_66\
-lboost_math_tr1-mgw63-mt-x32-1_66\
-lboost_math_tr1f-mgw63-mt-x32-1_66\
-lboost_math_tr1l-mgw63-mt-x32-1_66\
-lboost_prg_exec_monitor-mgw63-mt-x32-1_66\
-lboost_program_options-mgw63-mt-x32-1_66\
-lboost_random-mgw63-mt-x32-1_66\
-lboost_regex-mgw63-mt-x32-1_66\
-lboost_serialization-mgw63-mt-x32-1_66\
-lboost_signals-mgw63-mt-x32-1_66\
-lboost_stacktrace_basic-mgw63-mt-x32-1_66\
-lboost_stacktrace_noop-mgw63-mt-x32-1_66\
-lboost_system-mgw63-mt-x32-1_66\
-lboost_test_exec_monitor-mgw63-mt-x32-1_66\
-lboost_thread-mgw63-mt-x32-1_66\
-lboost_timer-mgw63-mt-x32-1_66\
-lboost_type_erasure-mgw63-mt-x32-1_66\
-lboost_unit_test_framework-mgw63-mt-x32-1_66\
-lboost_wave-mgw63-mt-x32-1_66\
-lboost_wserialization-mgw63-mt-x32-1_66\
but still the same problem, if the order matter what order i need to make this example work?, also if there is a way to add them all at once with a right order it will be better.
Thanks in advance.
I am trying to compile a cpp code using the header occi.h the code i am using is
`
#include <iostream>
#include <occi.h>
using namespace std;
int main(){
oracle::occi::Environment* environment;
oracle::occi::Connection *con;
oracle::occi::Statement* stmt;
oracle::occi::ResultSet* res;
try
{
environment = oracle::occi::Environment::createEnvironment(oracle::occi::Environment::DEFAULT);
con = environment->createConnection("sys", "root","xe");
stmt = con->createStatement("select * from customers");
res = stmt->executeQuery();
while (res->next())
std::cout<<res->getInt(1)<<" "<<res->getString(2)<<std::endl;
stmt->closeResultSet(res);
con->terminateStatement(stmt);
environment->terminateConnection(con);
}catch(oracle::occi::SQLException &e){
std::cout<<e.what();
}
return 0;
}`
i am getting the following errors when i run the following command :-
g++ -I /root/instantclient_11_2/sdk/include -L $ORACLE_HOME/lib:/root/Shared/instantclient_11_2_lib/ -L $ORACLE_HOME/rdbms/lib cpp_db_conn.cpp
error:-
/tmp/ccjcKsxz.o: In function main':
udf.cpp:(.text+0x26): undefined reference tooracle::occi::Environment::createEnvironment(oracle::occi::Environment::Mode, void*, void* ()(void, unsigned long), void* ()(void, void*, unsigned long), void ()(void, void*))'
/tmp/ccjcKsxz.o:(.gcc_except_table+0x80): undefined reference to `typeinfo for oracle::occi::SQLException'
collect2: ld returned 1 exit status
oracle::occi::Connection|why do you have a space here???|*|and not here???|con;
I can tell you my case.
Obviously, It is a bit-mismatch problem.
My environment is a 'Microsoft SDK v7.0' with 64bit compiler as a default
Unfortunately, my oracle client was a 32-bit, which version is instantclient-basic-nt-12.1.0.2.0.
I've got the same error with yours.
So, I change my compiler to 32-bit.
setenv /x86
Then, all problem was gone.
Have a good day.
I have install leveldb in my home directory ~/local like this.
[~/temp/leveldb-1.15.0] $ make
[~/temp/leveldb-1.15.0] $ cp -av libleveldb.* $HOME/local/lib/
[~/temp/leveldb-1.15.0] $ cp -av include/leveldb $HOME/local/include/
My c++ program like this:
#include <assert.h>
#include <iostream>
#include "leveldb/db.h"
using namespace std;
int main(int argc,char * argv[])
{
leveldb::DB* db;
leveldb::Options options;
options.create_if_missing = true;
std::string dbpath = "tdb";
leveldb::Status status = leveldb::DB::Open(options, dbpath, &db);
assert(status.ok());
std::string key1 = "grz";
std::string key2 = "grz-rt#63.com";
cout<<"Open db OK"<<std::endl;
std::string value;
leveldb::Status s ;
s = db->Put(leveldb::WriteOptions(), key1, key2);/*key1和key2作为一对key-value对插入*/
s = db->Get(leveldb::ReadOptions(), key1, &value);/*根据key返回对应的value值*/
cout<<value<<std::endl;
delete db;/*删除数据库*/
return 0;
}
I compile this C++ program like this:
g++ -o Main Main.cpp ~/local/lib/libleveldb.a -lpthread -I ~/local/include/
But I get the error like this:
/public/home/kli/local/lib/libleveldb.a(table_builder.o): In function `leveldb::TableBuilder::WriteBlock(leveldb::BlockBuilder*, leveldb::BlockHandle*)':
table_builder.cc:(.text+0x678): undefined reference to `snappy::MaxCompressedLength(unsigned long)'
table_builder.cc:(.text+0x6b2): undefined reference to `snappy::RawCompress(char const*, unsigned long, char*, unsigned long*)'
/public/home/kli/local/lib/libleveldb.a(format.o): In function `leveldb::ReadBlock(leveldb::RandomAccessFile*, leveldb::ReadOptions const&, leveldb::BlockHandle const&, leveldb::BlockContents*)':
format.cc:(.text+0x5de): undefined reference to `snappy::GetUncompressedLength(char const*, unsigned long, unsigned long*)'
format.cc:(.text+0x64e): undefined reference to `snappy::RawUncompress(char const*, unsigned long, char*)'
collect2: ld returned 1 exit status
I don't know what's wrong.
I am new to Linux. Thank you very much!
libleveldb.a misses Snappy when being linked which would be probably in libsnappy.a in the same directory.
Looks like the Makefile is incomplete.
With the current install, you need to edit the Makefile to link against snappy and to include -L/usr/local/lib instead of -L/usr/local/include.
(Will post pull request later)
I was looking for a lock-free hash table implementation in C or C++ and found one: SunriseDD. That was the good news :) For a few days I am trying to get this up and running but with no luck. I can compile downloaded sources as a static library using GCC C compiler. And I get libSunriseDD.a archive.
So far so good :D
I have created a simple C++ application to wrap the SunriseDD C implementation of the hash table. Here is the main.cpp:
#include <iostream>
#include <dd_data_dictionary.h>
using namespace std;
struct Node{
int oid;
int x, y;
};
struct HashTableEntry{
Node *node;
int idx;
};
void copyFunction(void * source, void * target){
target = source;
}
template<typename T>class HashTableDD{
private:
dd_dictionary objects;
public:
HashTableDD() {
objects = dd_new_dictionary(); // creating dictionary
dd_set_object_copy_function_for_dictionary(objects, copyFunction); // setting copy function
}
~HashTableDD() {
dd_dispose_dictionary(objects);
}
bool insert(T obj, long key){
return dd_add_object_for_key(objects, (char *)key, (void*)obj);
}
bool remove(long key){
return dd_remove_object_for_key(objects, (char *)key);
}
T find(long key) {
return (T)dd_object_for_key(objects, (char *)key, false);
}
};
int main(int argc, char ** argv){
HashTableDD<HashTableEntry*> *ht = new HashTableDD<HashTableEntry*>();
HashTableEntry* hte = new HashTableEntry;
hte->idx = 1;
hte->node = NULL;
ht->insert(hte, 1);
HashTableEntry* hte2 = new HashTableEntry;
hte2->idx = 2;
Node n;
n.oid = 10; n.x = 10; n.y = 10;
hte2->node = &n;
ht->insert(hte2, 2);
HashTableEntry* ret = ht->find(1);
if(ret != NULL){
cout << "hte. idx: " << ret->idx << " node: " << ret->node << endl;
}
ht->remove(1);
ht->remove(2);
delete hte; delete hte2; delete ht;
return 0;
}
But the linker is not happy about that:
:~/Desktop/HashTable$ make
Building file: main.cpp
Invoking: GCC C++ Compiler
g++ -ISunriseDD/build/../ -O0 -g3 -m64 -c -o"build/main.o" "main.cpp"
Finished building: main.cpp
Building target: build/HashTableDD
Invoking: GCC C++ Linker
g++ -LSunriseDD/build/ -lSunriseDD -o build/HashTableDD build/main.o
build/main.o: In function `HashTableDD':
/home/robertas/Desktop/HashTable/main.cpp:32: undefined reference to `dd_new_dictionary()'
/home/robertas/Desktop/HashTable/main.cpp:33: undefined reference to `dd_set_object_copy_function_for_dictionary(void*, void (*)(void*, void*))'
build/main.o: In function `HashTableDD<HashTableEntry*>::insert(HashTableEntry*, long)':
/home/robertas/Desktop/HashTable/main.cpp:40: undefined reference to `dd_add_object_for_key(void*, char const*, void*)'
build/main.o: In function `HashTableDD<HashTableEntry*>::find(long)':
/home/robertas/Desktop/HashTable/main.cpp:47: undefined reference to `dd_object_for_key(void*, char const*, bool)'
build/main.o: In function `HashTableDD<HashTableEntry*>::remove(long)':
/home/robertas/Desktop/HashTable/main.cpp:44: undefined reference to `dd_remove_object_for_key(void*, char const*)'
build/main.o: In function `~HashTableDD':
/home/robertas/Desktop/HashTable/main.cpp:36: undefined reference to `dd_dispose_dictionary(void*)'
collect2: ld returned 1 exit status
make: *** [build/HashTableDD] Error 1
Any ideas what am I doing wrong here? Do I link the SunriseDD library incorrectly?
BTW I have the following directory listing where my main.cpp resides:
+HashTable
|--+build
| |--main.o
|---main.cpp
|--+SunriseDD
|--+build
| |--libSunriseDD.a
| |--other object files
|--headers and source files of SunriseDD
Thanks for the help!
Put -lSunriseDD last on the linker line. The linker processes arguments left to right, and searches libraries for currently undefined symbols when it processes a static library.
Also, unless the library is C++-aware, wrap includes in extern "C".
extern "C" {
#include <dd_data_dictionary.h>
}