I am trying to experiment with the Poco library in order to send an email.
However when I try using the library I get an undefined error.
I think it has something to do with the compiler I used for Poco, but I am unsure which compiler I should use so that QT and Poco are compiled with the same thing.
Mass_Mailer.pro
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Mass_Mailer
TEMPLATE = app
SOURCES += main.cpp \
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
INCLUDEPATH += /usr/local/include/
main.cpp
#include "mainwindow.h"
#include <QApplication>
#include <iostream>
#include <Poco/Net/MailMessage.h>
#include <Poco/Net/MailRecipient.h>
#include <Poco/Net/SMTPClientSession.h>
#include <Poco/Net/NetException.h>
using namespace std;
using namespace Poco::Net;
using namespace Poco;
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
int sendmail()
{
string host = "mail.domain.com";
UInt16 port = 25;
string user = "xxx";
string password = "xxx";
string to = "xxx#domain.com";
string from = "xxx#domain.com";
string subject = "Your first e-mail message sent using Poco Libraries";
subject = MailMessage::encodeWord(subject.c_str(), "UTF-8");
string content = "Well done! You've successfully sent your first message using Poco SMTPClientSession";
MailMessage message;
message.setSender(from);
message.addRecipient(MailRecipient(MailRecipient::PRIMARY_RECIPIENT, to));
message.setSubject(subject);
message.setContentType("text/plain; charset=UTF-8");
message.setContent(content, MailMessage::ENCODING_8BIT);
try {
SMTPClientSession session(host, port);
session.open();
try {
session.login(SMTPClientSession::AUTH_LOGIN, user, password);
session.sendMessage(message);
cout << "Message successfully sent" << endl;
session.close();
} catch (SMTPException &e) {
cerr << e.displayText() << endl;
session.close();
return 0;
}
} catch (NetException &e) {
cerr << e.displayText() << endl;
return 0;
}
return 0;
}
Errors
main.o: In function `sendmail()':
/home/mongo/Cpp/Mass_Mailer/build-Mass_Mailer-Desktop-Debug/../Mass_Mailer/main.cpp:31: undefined reference to `Poco::Net::MailMessage::encodeWord(std::string const&, std::string const&)'
/home/mongo/Cpp/Mass_Mailer/build-Mass_Mailer-Desktop-Debug/../Mass_Mailer/main.cpp:33: undefined reference to `Poco::Net::MailMessage::MailMessage()'
/home/mongo/Cpp/Mass_Mailer/build-Mass_Mailer-Desktop-Debug/../Mass_Mailer/main.cpp:34: undefined reference to `Poco::Net::MailMessage::setSender(std::string const&)'
/home/mongo/Cpp/Mass_Mailer/build-Mass_Mailer-Desktop-Debug/../Mass_Mailer/main.cpp:35: undefined reference to `Poco::Net::MailRecipient::MailRecipient(Poco::Net::MailRecipient::RecipientType, std::string const&)'
/home/mongo/Cpp/Mass_Mailer/build-Mass_Mailer-Desktop-Debug/../Mass_Mailer/main.cpp:35: undefined reference to `Poco::Net::MailMessage::addRecipient(Poco::Net::MailRecipient const&)'
/home/mongo/Cpp/Mass_Mailer/build-Mass_Mailer-Desktop-Debug/../Mass_Mailer/main.cpp:35: undefined reference to `Poco::Net::MailRecipient::~MailRecipient()'
/home/mongo/Cpp/Mass_Mailer/build-Mass_Mailer-Desktop-Debug/../Mass_Mailer/main.cpp:36: undefined reference to `Poco::Net::MailMessage::setSubject(std::string const&)'
/home/mongo/Cpp/Mass_Mailer/build-Mass_Mailer-Desktop-Debug/../Mass_Mailer/main.cpp:37: undefined reference to `Poco::Net::MailMessage::setContentType(std::string const&)'
/home/mongo/Cpp/Mass_Mailer/build-Mass_Mailer-Desktop-Debug/../Mass_Mailer/main.cpp:38: undefined reference to `Poco::Net::MailMessage::setContent(std::string const&, Poco::Net::MailMessage::ContentTransferEncoding)'
/home/mongo/Cpp/Mass_Mailer/build-Mass_Mailer-Desktop-Debug/../Mass_Mailer/main.cpp:40: undefined reference to `Poco::Net::SMTPClientSession::SMTPClientSession(std::string const&, unsigned short)'
/home/mongo/Cpp/Mass_Mailer/build-Mass_Mailer-Desktop-Debug/../Mass_Mailer/main.cpp:41: undefined reference to `Poco::Net::SMTPClientSession::open()'
/home/mongo/Cpp/Mass_Mailer/build-Mass_Mailer-Desktop-Debug/../Mass_Mailer/main.cpp:43: undefined reference to `Poco::Net::SMTPClientSession::login(Poco::Net::SMTPClientSession::LoginMethod, std::string const&, std::string const&)'
/home/mongo/Cpp/Mass_Mailer/build-Mass_Mailer-Desktop-Debug/../Mass_Mailer/main.cpp:44: undefined reference to `Poco::Net::SMTPClientSession::sendMessage(Poco::Net::MailMessage const&)'
/home/mongo/Cpp/Mass_Mailer/build-Mass_Mailer-Desktop-Debug/../Mass_Mailer/main.cpp:46: undefined reference to `Poco::Net::SMTPClientSession::close()'
/home/mongo/Cpp/Mass_Mailer/build-Mass_Mailer-Desktop-Debug/../Mass_Mailer/main.cpp:46: undefined reference to `Poco::Net::SMTPClientSession::~SMTPClientSession()'
/home/mongo/Cpp/Mass_Mailer/build-Mass_Mailer-Desktop-Debug/../Mass_Mailer/main.cpp:33: undefined reference to `Poco::Net::MailMessage::~MailMessage()'
/home/mongo/Cpp/Mass_Mailer/build-Mass_Mailer-Desktop-Debug/../Mass_Mailer/main.cpp:35: undefined reference to `Poco::Net::MailRecipient::~MailRecipient()'
/home/mongo/Cpp/Mass_Mailer/build-Mass_Mailer-Desktop-Debug/../Mass_Mailer/main.cpp:48: undefined reference to `Poco::Exception::displayText() const'
/home/mongo/Cpp/Mass_Mailer/build-Mass_Mailer-Desktop-Debug/../Mass_Mailer/main.cpp:49: undefined reference to `Poco::Net::SMTPClientSession::close()'
/home/mongo/Cpp/Mass_Mailer/build-Mass_Mailer-Desktop-Debug/../Mass_Mailer/main.cpp:51: undefined reference to `Poco::Net::SMTPClientSession::~SMTPClientSession()'
/home/mongo/Cpp/Mass_Mailer/build-Mass_Mailer-Desktop-Debug/../Mass_Mailer/main.cpp:53: undefined reference to `Poco::Exception::displayText() const'
/home/mongo/Cpp/Mass_Mailer/build-Mass_Mailer-Desktop-Debug/../Mass_Mailer/main.cpp:33: undefined reference to `Poco::Net::MailMessage::~MailMessage()'
main.o:(.gcc_except_table+0x120): undefined reference to `typeinfo for Poco::Net::SMTPException'
main.o:(.gcc_except_table+0x124): undefined reference to `typeinfo for Poco::Net::NetException'
collect2: error: ld returned 1 exit status
make: *** [Mass_Mailer] Error 1
11:45:01: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project Mass_Mailer (kit: Desktop)
When executing step 'Make'11:45:01: Elapsed time: 00:02.
You need to link Poco libraries to your project. In the project file, add something like this:
LIBS += -lPocoNet -lPocoFoundation
Related
I am pretty new to c and c++, so please try explain more specific what I should do. The program tries to read files from a directory using multithreads, and store the information in a map so that it can be used later.
I have been looking for similar posts. However, I am not able to figure out.
In https://github.com/kaldi-asr/kaldi/issues/938, it said that "If you get linker errors about undefined references to symbols that involve types in the std::__cxx11 namespace or the tag [abi:cxx11] then it probably indicates that you are trying to link together object files that were compiled with different values for the _GLIBCXX_USE_CXX11_ABI macro."
The solution for undefined reference to `pthread_cancel' (add "-pthread" flag does not work either.
My code is
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <map>
#include <algorithm>
#include <random>
#include <unistd.h>
#include <cmath>
#include <stdlib.h>
#include <mutex>
#include <sys/wait.h>
#include <filesystem>
#include <string>
#include <pthread.h>
#define time_str(s) (s < 60 ? (to_string(s) + " second(s)") : (s < 3600 ? (to_string((s) / 60) + " minute(s)") : (to_string((s) / 3600) + " hour(s) and " + to_string(((s) % 3600) / 60) + " minute(s)")))
using namespace std;
namespace fs = std::filesystem;
struct MyGenom
{
vector<string> filepaths;
map<string, string> seq;
};
void check_rv(int rv) {
if (rv != 0) {
printf("Error: Value is %d\n", rv);
exit(1);
}
}
struct Reference_Genome {
static long unsigned int idx;
static map <string, string> seq;
static pthread_mutex_t mtxLock;
static vector <string> filepaths;
static void writing(string path) {
}
static void *distribution(void *var) {
}
Reference_Genome(string dir, unsigned int n_threads) {
}
};
int main(int argc, char const *argv[]) {
string dir = "./data/ex_seq";
unsigned int n_threads = 5;
Reference_Genome ref(dir, n_threads);
cout << "chr6: " << ref.seq["chr6"] << endl;
cout << "chr9: " << ref.seq["chr9"] << endl;
cout << "chr13: " << ref.seq["chr13"] << endl;
}
The gcc version is "Thread model: posix
gcc version 9.3.0 (Ubuntu 9.3.0-10ubuntu2)".
The error is
testSeq.cpp:97: undefined reference to `Reference_Genome::seq[abi:cxx11]'
/usr/bin/ld: testSeq.cpp:98: undefined reference to `Reference_Genome::seq[abi:cxx11]'
/usr/bin/ld: testSeq.cpp:99: undefined reference to `Reference_Genome::seq[abi:cxx11]'
/usr/bin/ld: /tmp/cctfwVX2.o: in function `Reference_Genome::writing(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
/testSeq.cpp:46: undefined reference to `Reference_Genome::seq[abi:cxx11]'
/usr/bin/ld: testSeq.cpp:48: undefined reference to `Reference_Genome::seq[abi:cxx11]'
/usr/bin/ld: /tmp/cctfwVX2.o: in function `Reference_Genome::distribution(void*)':
testSeq.cpp:55: undefined reference to `Reference_Genome::filepaths[abi:cxx11]'
/usr/bin/ld: testSeq.cpp:55: undefined reference to `Reference_Genome::idx'
/usr/bin/ld: testSeq.cpp:56: undefined reference to `Reference_Genome::mtxLock'
/usr/bin/ld: testSeq.cpp:57: undefined reference to `Reference_Genome::idx'
/usr/bin/ld: testSeq.cpp:57: undefined reference to `Reference_Genome::filepaths[abi:cxx11]'
/usr/bin/ld: testSeq.cpp:58: undefined reference to `Reference_Genome::idx'
/usr/bin/ld: testSeq.cpp:58: undefined reference to `Reference_Genome::idx'
/usr/bin/ld: testSeq.cpp:59: undefined reference to `Reference_Genome::mtxLock'
/usr/bin/ld: /tmp/cctfwVX2.o: in function `Reference_Genome::Reference_Genome(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned int)':
testSeq.cpp:68: undefined reference to `Reference_Genome::filepaths[abi:cxx11]'
/usr/bin/ld: testSeq.cpp:70: undefined reference to `Reference_Genome::idx'
/usr/bin/ld: testSeq.cpp:72: undefined reference to `Reference_Genome::mtxLock'
/usr/bin/ld: testSeq.cpp:85: undefined reference to `Reference_Genome::mtxLock'
/usr/bin/ld: testSeq.cpp:88: undefined reference to `Reference_Genome::filepaths[abi:cxx11]'
collect2: error: ld returned 1 exit status
When you declare static variables inside a class, you must also declare it exactly once outside of the class. In this case, you could put this in the bottom of your C++ file or in between the main() function and the class Reference_Genome definition:
long unsigned int Reference_Genome::idx;
map <string, string> Reference_Genome::seq;
pthread_mutex_t Reference_Genome::mtxLock;
vector <string> Reference_Genome::filepaths;
The idea is that you can put the class definition inside a header file, to be included in multiple different compilation units, but the static variables are only defined once, in one .cpp file of your choosing.
I am new at OpenCv. I am using Eclipse C/C++. When i try to run this sample code i faced with these errors. What should i do to solve this problem? Is there any problem at configurating ?
#using namespace std;
#using namespace cv;
int main( int argc, const char** argv )
{
Mat img = imread("MyPic.JPG", CV_LOAD_IMAGE_UNCHANGED);
if (img.empty()) //check whether the image is loaded or not
{
cout << "Error : Image cannot be loaded..!!" << endl;
//system("pause"); //wait for a key press
return -1;
}
namedWindow("MyWindow", CV_WINDOW_AUTOSIZE); //create a window with the name "MyWindow"
imshow("MyWindow", img); /
waitKey(0); //wait infinite time for a keypress
destroyWindow("MyWindow"); //destroy the window with the name, "MyWindow"
return 0;
}
16:11:28 **** Incremental Build of configuration Debug for project OpenCv ****
Info: Internal Builder is used for build
g++ "-IC:\\opencv\\build\\include" -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\OpenCv.o" "..\\src\\OpenCv.cpp"
g++ "-LC:\\opencv\\build\\x86\\vc12\\lib" -o OpenCv.exe "src\\OpenCv.o" -lopencv_calib3d249 -lopencv_contrib249 -lopencv_core249 -lopencv_features2d249 -lopencv_flann249 -lopencv_gpu249 -lopencv_highgui249 -lopencv_imgproc249 -lopencv_legacy249 -lopencv_ml249 -lopencv_nonfree249 -lopencv_objdetect249 -lopencv_ocl249 -lopencv_photo249 -lopencv_stitching249 -lopencv_superres249 -lopencv_ts249 -lopencv_video249 -lopencv_videostab249
src\OpenCv.o: In function `main':
C:\Users\ayberk101\workspace\OpenCv\Debug/../src/OpenCv.cpp:10: undefined reference to `cv::imread(std::string const&, int)'
C:\Users\ayberk101\workspace\OpenCv\Debug/../src/OpenCv.cpp:19: undefined reference to `cv::namedWindow(std::string const&, int)'
C:\Users\ayberk101\workspace\OpenCv\Debug/../src/OpenCv.cpp:20: undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
C:\Users\ayberk101\workspace\OpenCv\Debug/../src/OpenCv.cpp:20: undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'
C:\Users\ayberk101\workspace\OpenCv\Debug/../src/OpenCv.cpp:22: undefined reference to `cv::waitKey(int)'
C:\Users\ayberk101\workspace\OpenCv\Debug/../src/OpenCv.cpp:24: undefined reference to `cv::destroyWindow(std::string const&)'
src\OpenCv.o: In function `ZN2cv3MatD1Ev':
C:/opencv/build/include/opencv2/core/mat.hpp:278: undefined reference to `cv::fastFree(void*)'
src\OpenCv.o: In function `ZN2cv3Mat7releaseEv':
C:/opencv/build/include/opencv2/core/mat.hpp:367: undefined reference to `cv::Mat::deallocate()'
collect2.exe: error: ld returned 1 exit status
problem1: you will have to include opencv / c++ header files to make it work:
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#using namespace cv;
#include <iostream>
#using namespace std;
int main() {
...
then, problem2: you cannot use the vc12 libs with mingw. (it's a different compiler)
there are no more prebuild mingw libs for opencv, so, before doing anything else, you will have to build the opencv libs locally using cmake.
again, do you really need to use mingw / eclipse ? (vs express is still free)
I am writing a C++ app for Windows using Code Blocks IDE. I am interested in using the following XML++ library: http://libxmlplusplus.sourceforge.net/
It requires libxml2 and glibmm-2.4 libraries. I downloaded the source for each of these libraries and included all of the headers into my project by right clicking on "Build Options" ==> "Search Directories" tab ==> "Compiler" tab. I specified the header include files there. I modified the main.cpp file using the source code from "examples/dom_parser" from the xml++/examples directory.
Now, I am having trouble with the following error message. I have never "linked" or used *.lib, *.dll files before... but I am now getting the following "undefined reference" error messages. Please let me know what I'd need to do in order to build this. Is there a particular file that I need to "link" and if so, where are these files located? I can't seem to find them in the source files that I extracted. Could you help with specific instructions on which files to include and which folders they might be located in? I am using the CodeBlocks IDE.
Could someone replicate the project on your Windows 64 bit PC and see if it is able to run correctly?
Thank you.
UPDATE
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:44: undefined reference to `xmlpp::ContentNode::is_white_space() const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:47: undefined reference to `xmlpp::Node::get_name() const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:49: undefined reference to `Glib::ustring::empty() const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:53: undefined reference to `xmlpp::Node::get_namespace_prefix() const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:54: undefined reference to `Glib::ustring::empty() const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:55: undefined reference to `Glib::operator<<(std::ostream&, Glib::ustring const&)'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:57: undefined reference to `Glib::operator<<(std::ostream&, Glib::ustring const&)'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:57: undefined reference to `Glib::operator<<(std::ostream&, Glib::ustring const&)'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:57: undefined reference to `Glib::ustring::~ustring()'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:69: undefined reference to `xmlpp::ContentNode::get_content() const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:69: undefined reference to `Glib::operator<<(std::ostream&, Glib::ustring const&)'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:69: undefined reference to `Glib::ustring::~ustring()'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:74: undefined reference to `xmlpp::ContentNode::get_content() const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:74: undefined reference to `Glib::operator<<(std::ostream&, Glib::ustring const&)'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:74: undefined reference to `Glib::ustring::~ustring()'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:79: undefined reference to `xmlpp::ContentNode::get_content() const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:79: undefined reference to `Glib::operator<<(std::ostream&, Glib::ustring const&)'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:79: undefined reference to `Glib::ustring::~ustring()'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:87: undefined reference to `xmlpp::Node::get_line() const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:90: undefined reference to `xmlpp::Element::get_attributes() const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:96: undefined reference to `xmlpp::Node::get_namespace_prefix() const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:97: undefined reference to `Glib::ustring::empty() const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:98: undefined reference to `xmlpp::Attribute::get_value() const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:98: undefined reference to `xmlpp::Attribute::get_name() const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:98: undefined reference to `Glib::operator<<(std::ostream&, Glib::ustring const&)'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:98: undefined reference to `Glib::operator<<(std::ostream&, Glib::ustring const&)'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:98: undefined reference to `Glib::ustring::~ustring()'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:98: undefined reference to `Glib::ustring::~ustring()'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:100: undefined reference to `xmlpp::Attribute::get_value() const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:100: undefined reference to `xmlpp::Attribute::get_name() const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:100: undefined reference to `Glib::operator<<(std::ostream&, Glib::ustring const&)'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:100: undefined reference to `Glib::operator<<(std::ostream&, Glib::ustring const&)'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:100: undefined reference to `Glib::operator<<(std::ostream&, Glib::ustring const&)'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:100: undefined reference to `Glib::ustring::~ustring()'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:100: undefined reference to `Glib::ustring::~ustring()'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:101: undefined reference to `Glib::ustring::~ustring()'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:103: undefined reference to `Glib::ustring::ustring()'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:103: undefined reference to `Glib::ustring::ustring(char const*)'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:103: undefined reference to `xmlpp::Element::get_attribute(Glib::ustring const&, Glib::ustring const&) const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:103: undefined reference to `Glib::ustring::~ustring()'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:103: undefined reference to `Glib::ustring::~ustring()'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:106: undefined reference to `xmlpp::Attribute::get_value() const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:106: undefined reference to `Glib::operator<<(std::ostream&, Glib::ustring const&)'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:106: undefined reference to `Glib::ustring::~ustring()'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:113: undefined reference to `Glib::ustring::ustring()'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:113: undefined reference to `xmlpp::Node::get_children(Glib::ustring const&) const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:113: undefined reference to `Glib::ustring::~ustring()'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:118: undefined reference to `Glib::ustring::~ustring()'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:57: undefined reference to `Glib::ustring::~ustring()'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:69: undefined reference to `Glib::ustring::~ustring()'
**UPDATED 02/11/2014 - at 10:45am **
Hi. Thanks for your suggestion. I ended up downloading the following ( http://ftp.gnome.org/pub/gnome/binaries/win32/gtkmm/2.22/ ) the entire gtkmm-win32-devel-2.22.0-2.exe and installed it onto my Windows PC in C:\gtkmm. Then, I modified my project by including the header files, library files, and bin files. Here are the screen shots:
After building, I am now seeing 0 errors and 0 warning messages. However, it appears to CRASH. I have no idea why. It seems that the gtk installation uses libxml++ version 2.6. This is fine. I downloaded the libxml++ 2.6 from the website to see the examples that they provided. I used the following source code in my main.cc. Do you know what is the problem?
// -*- C++ -*-
/* main.cc
*
* Copyright (C) 2002 The libxml++ development team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <libxml++/libxml++.h>
#include <iostream>
void print_indentation(unsigned int indentation)
{
for(unsigned int i = 0; i < indentation; ++i)
std::cout << " ";
}
void print_node(const xmlpp::Node* node, unsigned int indentation = 0)
{
std::cout << std::endl; //Separate nodes by an empty line.
const xmlpp::ContentNode* nodeContent = dynamic_cast<const xmlpp::ContentNode*>(node);
const xmlpp::TextNode* nodeText = dynamic_cast<const xmlpp::TextNode*>(node);
const xmlpp::CommentNode* nodeComment = dynamic_cast<const xmlpp::CommentNode*>(node);
if(nodeText && nodeText->is_white_space()) //Let's ignore the indenting - you don't always want to do this.
return;
Glib::ustring nodename = node->get_name();
if(!nodeText && !nodeComment && !nodename.empty()) //Let's not say "name: text".
{
print_indentation(indentation);
std::cout << "Node name = " << node->get_name() << std::endl;
std::cout << "Node name = " << nodename << std::endl;
}
else if(nodeText) //Let's say when it's text. - e.g. let's say what that white space is.
{
print_indentation(indentation);
std::cout << "Text Node" << std::endl;
}
//Treat the various node types differently:
if(nodeText)
{
print_indentation(indentation);
std::cout << "text = \"" << nodeText->get_content() << "\"" << std::endl;
}
else if(nodeComment)
{
print_indentation(indentation);
std::cout << "comment = " << nodeComment->get_content() << std::endl;
}
else if(nodeContent)
{
print_indentation(indentation);
std::cout << "content = " << nodeContent->get_content() << std::endl;
}
else if(const xmlpp::Element* nodeElement = dynamic_cast<const xmlpp::Element*>(node))
{
//A normal Element node:
//line() works only for ElementNodes.
print_indentation(indentation);
std::cout << " line = " << node->get_line() << std::endl;
//Print attributes:
const xmlpp::Element::AttributeList& attributes = nodeElement->get_attributes();
for(xmlpp::Element::AttributeList::const_iterator iter = attributes.begin(); iter != attributes.end(); ++iter)
{
const xmlpp::Attribute* attribute = *iter;
print_indentation(indentation);
std::cout << " Attribute " << attribute->get_name() << " = " << attribute->get_value() << std::endl;
}
const xmlpp::Attribute* attribute = nodeElement->get_attribute("title");
if(attribute)
{
std::cout << "title found: =" << attribute->get_value() << std::endl;
}
}
if(!nodeContent)
{
//Recurse through child nodes:
xmlpp::Node::NodeList list = node->get_children();
for(xmlpp::Node::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter)
{
print_node(*iter, indentation + 2); //recursive
}
}
}
int main(int argc, char* argv[])
{
Glib::ustring filepath;
if(argc > 1 )
filepath = argv[1]; //Allow the user to specify a different XML file to parse.
else
filepath = "example.xml";
try
{
xmlpp::DomParser parser;
parser.set_validate();
parser.set_substitute_entities(); //We just want the text to be resolved/unescaped automatically.
parser.parse_file(filepath);
if(parser)
{
//Walk the tree:
const xmlpp::Node* pNode = parser.get_document()->get_root_node(); //deleted by DomParser.
print_node(pNode);
}
}
catch(const std::exception& ex)
{
std::cout << "Exception caught: " << ex.what() << std::endl;
}
return 0;
}
Are libxml2 and glibmm-2.4 built?
You can find prebuilt windows binaries for libxml2 here. I can't find prebuilt windows binaries for glibmm, so you'll either have to download the entire gtkmm installer, or build it yourself.
After this process is done, you should have files such as
libxml2.lib
libxml2.a
libxml2.dll
Depending on you compiler (GCC or MSVC), and the desired linking method (static or dynamic), you should choose the required library files.
In Code::Blocks you do the linking via the "Linker settings" tab, accessible through Project -> Build options... -> Linker settings. Click add and select the previously compiled
library files (libxml2, glibmm-2.4 and libxml++) using the folder browser.
Update: I am able to successfully run the project on my Windows 8 64-bit PC.
I have a MinGW-64 installation from MinGW-builds (GCC 4.8.1). The only other thing I had to download was the gtkmm-win64 installer. I chose the "full installation".
The search directories in the project build settings were:
C:\gtkmm64\include
C:\gtkmm64\include\libxml++-2.6
C:\gtkmm64\include\glibmm-2.4
C:\gtkmm64\include\glib-2.0
C:\gtkmm64\lib\glibmm-2.4\include
C:\gtkmm64\lib\glib-2.0\include
C:\gtkmm64\lib\libxml++-2.6\include
The import libraries to link to were:
C:\gtkmm64\lib\libxml++-2.6.dll.a
C:\gtkmm64\lib\libglibmm-2.4.dll.a
C:\gtkmm64\lib\libglibmm_generate_extra_defs-2.4.dll.a
And the DLL's copied to the executable's location from the gtkmm64\bin folder were:
libglib-2.0-0.dll
libglibmm-2.4-1.dll
libglibmm_generate_extra_defs-2.4-1.dll
libxml++-2.6-2.dll
libxml2-2.dll
The executable ran successfully (excluding the fact that the program terminated due to some parsing exception).
I am trying to call R functions from C++ on Windows. I am using MinGW for compiling the program, but it throws error while compiling. Code (taken from Dirk) and compilation error are as follows:
#include <iostream>
using namespace std;
#include "RInside.h" // for the embedded R via RInside
Rcpp::NumericMatrix createMatrix(const int n) {
Rcpp::NumericMatrix M(n,n);
for (int i=0; i<n; i++) {
for (int j=0; j<n; j++) {
M(i,j) = i*10+j;
}
}
return(M);
}
int main(int argc, char *argv[]) {
const int mdim = 4; // let the matrices be 4 by 4
SEXP ans;
RInside R(argc, argv); // create an embedded R instance
Rcpp::NumericMatrix M = createMatrix(mdim); // create and fill a sample data Matrix
R["M"] = M; // assign C++ matrix M to R's 'M' var
std::string evalstr = "\
cat('Running ls()\n'); print(ls()); \
cat('Showing M\n'); print(M); \
cat('Showing colSums()\n'); Z <- colSums(M); print(Z); \
Z"; // returns Z
ans = R.parseEval(evalstr); // eval the init string -- Z is now in ans
Rcpp::NumericVector v(ans); // convert SEXP ans to a vector of doubles
for (int i=0; i< v.size(); i++) { // show the result
std::cout << "In C++ element " << i << " is " << v[i] << std::endl;
}
return 0;
}
Compile:
g++ -I "C:\ProgramFiles\R\R-2.14.0\library\RInside\include" -I "C:\Progra
mFiles\R\R-2.14.0\library\Rcpp\include" -I "C:\ProgramFiles\R\R-2.14.0\include"
RFunctions.cpp -o sh1.exe
Error:
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text+0x19a): und
efined reference to `RInside::RInside(int, char const* const*, bool)'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text+0x1ee): und
efined reference to `RInside::operator[](std::string const&)'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text+0x26d): und
efined reference to `RInside::parseEval(std::string const&)'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text+0x35b): und
efined reference to `RInside::~RInside()'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text+0x3e1): und
efined reference to `RInside::~RInside()'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp7RO
bjectC2Ev[Rcpp::RObject::RObject()]+0x8): undefined reference to `vtable for Rcp
p::RObject'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp7RO
bjectC2Ev[Rcpp::RObject::RObject()]+0xd): undefined reference to `_imp__R_NilVal
ue'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN7RInside
5ProxyD1Ev[RInside::Proxy::~Proxy()]+0xd): undefined reference to `Rcpp::RObject
::~RObject()'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp6Ve
ctorILi14EED2Ev[Rcpp::Vector<14>::~Vector()]+0x16): undefined reference to `Rcpp
::RObject::~RObject()'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp6Ve
ctorILi14EED1Ev[Rcpp::Vector<14>::~Vector()]+0x16): undefined reference to `Rcpp
::RObject::~RObject()'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp6Ve
ctorILi14EEC1EP7SEXPREC[Rcpp::Vector<14>::Vector(SEXPREC*)]+0x57): undefined ref
erence to `Rcpp::RObject::setSEXP(SEXPREC*)'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp6Ve
ctorILi14EEC1EP7SEXPREC[Rcpp::Vector<14>::Vector(SEXPREC*)]+0x66): undefined ref
erence to `Rcpp::RObject::~RObject()'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp6Ma
trixILi14EEC1ERKiS3_[Rcpp::Matrix<14>::Matrix(int const&, int const&)]+0x2c): un
defined reference to `Rcpp::Dimension::Dimension(unsigned int const&, unsigned i
nt const&)'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZNK4Rcpp6V
ectorILi14EE4sizeEv[Rcpp::Vector<14>::size() const]+0x10): undefined reference t
o `Rf_length'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp6r_
castILi14EEEP7SEXPRECS2_[SEXPREC* Rcpp::r_cast<14>(SEXPREC*)]+0xd): undefined re
ference to `TYPEOF'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp6r_
castILi14EEEP7SEXPRECS2_[SEXPREC* Rcpp::r_cast<14>(SEXPREC*)]+0x1d): undefined r
eference to `SEXPREC* Rcpp::internal::r_true_cast<14>(SEXPREC*)'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp6Ve
ctorILi14EEC2ERKNS_9DimensionE[Rcpp::Vector<14>::Vector(Rcpp::Dimension const&)]
+0x46): undefined reference to `Rcpp::Dimension::prod() const'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp6Ve
ctorILi14EEC2ERKNS_9DimensionE[Rcpp::Vector<14>::Vector(Rcpp::Dimension const&)]
+0x56): undefined reference to `Rf_allocVector'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp6Ve
ctorILi14EEC2ERKNS_9DimensionE[Rcpp::Vector<14>::Vector(Rcpp::Dimension const&)]
+0x67): undefined reference to `Rcpp::RObject::setSEXP(SEXPREC*)'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp6Ve
ctorILi14EEC2ERKNS_9DimensionE[Rcpp::Vector<14>::Vector(Rcpp::Dimension const&)]
+0x7d): undefined reference to `Rcpp::Dimension::size() const'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp6Ve
ctorILi14EEC2ERKNS_9DimensionE[Rcpp::Vector<14>::Vector(Rcpp::Dimension const&)]
+0xc9): undefined reference to `Rcpp::RObject::attr(std::string const&) const'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp6Ve
ctorILi14EEC2ERKNS_9DimensionE[Rcpp::Vector<14>::Vector(Rcpp::Dimension const&)]
+0x13b): undefined reference to `Rcpp::RObject::~RObject()'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZNK4Rcpp11
Environment6assignINS_6MatrixILi14EEEEEbRKSsRKT_[bool Rcpp::Environment::assign<
Rcpp::Matrix<14> >(std::basic_string<char, std::char_traits<char>, std::allocato
r<char> > const&, Rcpp::Matrix<14> const&) const]+0x23): undefined reference to
`Rcpp::Environment::assign(std::string const&, SEXPREC*) const'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp7RO
bject14AttributeProxyaSINS_9DimensionEEERS1_RKT_[Rcpp::RObject::AttributeProxy&
Rcpp::RObject::AttributeProxy::operator=<Rcpp::Dimension>(Rcpp::Dimension const&
)]+0x1c): undefined reference to `Rcpp::RObject::AttributeProxy::set(SEXPREC*) c
onst'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp8in
ternal13r_init_vectorILi14EEEvP7SEXPREC[void Rcpp::internal::r_init_vector<14>(S
EXPREC*)]+0xd): undefined reference to `double* Rcpp::internal::r_vector_start<1
4, double>(SEXPREC*)'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp8in
ternal13r_init_vectorILi14EEEvP7SEXPREC[void Rcpp::internal::r_init_vector<14>(S
EXPREC*)]+0x23): undefined reference to `Rf_length'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp8in
ternal21wrap_dispatch_unknownINS_9DimensionEEEP7SEXPRECRKT_NS_6traits17integral_
constantIbLb1EEE[SEXPREC* Rcpp::internal::wrap_dispatch_unknown<Rcpp::Dimension>
(Rcpp::Dimension const&, Rcpp::traits::integral_constant<bool, true>)]+0xd): und
efined reference to `Rcpp::Dimension::operator SEXPREC*() const'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp6tr
aits14r_vector_cacheILi14EE6updateERKNS_6VectorILi14EEE[Rcpp::traits::r_vector_c
ache<14>::update(Rcpp::Vector<14> const&)]+0x15): undefined reference to `double
* Rcpp::internal::r_vector_start<14, double>(SEXPREC*)'
collect2: ld returned 1 exit status
Any ideas what I am missing?
Jim is correct in his earlier answer, but there is more.
When using RInside , you also need to
include and link with Rcpp (which RInside depends upon) a
include and link with R (which both depends upon) as well as of course
RInside's own library
The easiest way of doing this is to simply use the Makefile from the examples/standard directory --- given that you copied the code of one of the examples, you should also copy the build instructions.
Lastly, and that is your biggest issue: RInside applications do not currently work on Windows, which is clearly documented on the RInside page. It will build, but segfault on startup. Debugging help would be appreciated, this works on OS X and Linux.
You're not actually linking in the R library (whatever that is).
I try to write a webserver. As far as I am, it works quiet good with Windows. But I want to make it also Unix compatible. And I think there has to be a problem with the heredity f the exception class.
For better understanding, just the important parts:
server.cpp
#include <exception>
#include <stdexcept>
#ifdef __unix__
#include "UnixSocket.h"
#elif __WIN32__ || _MSC_VER
#include "WinSocket.h"
#endif
#include "HTTPParser.h"
int main(void) {
try {
socket->socketInit(PORT);
}
catch (exception &e) {
cout << endl << "Exception: " << e.what() << endl;
socket->cleanAll();
}
return 0
}
NetInterface.h
class NetInterface : public exception {
private:
public:
virtual void socketInit(const char *port) = 0;
virtual void cleanAll(void) = 0;
virtual void cleanPersCon(void) = 0;
virtual char *akzeptieren(void) = 0;
virtual void empfangen(void) = 0;
virtual void senden(void) = 0;
virtual void *get_in_addr(struct sockaddr *sa) = 0;
virtual string getIncoming(void) = 0;
virtual void setOutcoming(string s) = 0;
virtual ~NetInterface() throw() {};
};
UnixSocket.h
class UnixSocket : virtual public NetInterface {
private:
[...]
public:
UnixSocket(void);
//kill socket connections
void cleanAll(void);
void cleanPersCon(void);
//SysCalls
void socketInit(const char *port);
char *akzeptieren(void);
void empfangen(void);
void senden(void);
//Getter and Setter
string getIncoming(void);
void setOutcoming(string s);
virtual ~UnixSocket() throw() {};
};
HTTPParser.h
class HTTPParser : public exception {
private:
[...]
public:
HTTPParser(NetInterface *_socket, string _path);
void parsePacket(void);
virtual ~HTTPParser() throw() {};
};
There you can se a short summary of the class declarations.
But now the gcc tells me something like this:
/tmp/cc8DNmKI.o:(.rodata._ZTV10HTTPParser[vtable for HTTPParser]+0x10): undefined reference to `std::exception::what() const'
/tmp/cc8DNmKI.o:(.rodata._ZTV10UnixSocket[vtable for UnixSocket]+0x14): undefined reference to `std::exception::what() const'
/tmp/cc8DNmKI.o:(.rodata._ZTV10UnixSocket[vtable for UnixSocket]+0x78): undefined reference to `std::exception::what() const'
/tmp/cc8DNmKI.o:(.rodata._ZTV12NetInterface[vtable for NetInterface]+0x10): undefined reference to `std::exception::what() const'
/tmp/cc8DNmKI.o:(.rodata._ZTV12NetInterface[vtable for NetInterface]+0x14): undefined reference to `__cxa_pure_virtual'
/tmp/cc8DNmKI.o:(.rodata._ZTV12NetInterface[vtable for NetInterface]+0x18): undefined reference to `__cxa_pure_virtual'
/tmp/cc8DNmKI.o:(.rodata._ZTV12NetInterface[vtable for NetInterface]+0x1c): undefined reference to `__cxa_pure_virtual'
/tmp/cc8DNmKI.o:(.rodata._ZTV12NetInterface[vtable for NetInterface]+0x20): undefined reference to `__cxa_pure_virtual'
/tmp/cc8DNmKI.o:(.rodata._ZTV12NetInterface[vtable for NetInterface]+0x24): undefined reference to `__cxa_pure_virtual'
/tmp/cc8DNmKI.o:(.rodata._ZTV12NetInterface[vtable for NetInterface]+0x28): more undefined references to `__cxa_pure_virtual' follow
/tmp/cc8DNmKI.o:(.rodata._ZTVSt16invalid_argument[vtable for std::invalid_argument]+0x10): undefined reference to `std::logic_error::what() const'
/tmp/cc8DNmKI.o:(.rodata._ZTVSt12domain_error[vtable for std::domain_error]+0x10): undefined reference to `std::logic_error::what() const'
/tmp/cc8DNmKI.o:(.rodata._ZTI10HTTPParser[typeinfo for HTTPParser]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
/tmp/cc8DNmKI.o:(.rodata._ZTI10HTTPParser[typeinfo for HTTPParser]+0x8): undefined reference to `typeinfo for std::exception'
/tmp/cc8DNmKI.o:(.rodata._ZTI10UnixSocket[typeinfo for UnixSocket]+0x0): undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
/tmp/cc8DNmKI.o:(.rodata._ZTI10UnixSocket[typeinfo for UnixSocket]+0x18): undefined reference to `typeinfo for std::exception'
/tmp/cc8DNmKI.o:(.rodata._ZTI12NetInterface[typeinfo for NetInterface]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
/tmp/cc8DNmKI.o:(.rodata._ZTI12NetInterface[typeinfo for NetInterface]+0x8): undefined reference to `typeinfo for std::exception'
/tmp/cc8DNmKI.o:(.rodata._ZTISt16invalid_argument[typeinfo for std::invalid_argument]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
/tmp/cc8DNmKI.o:(.rodata._ZTISt16invalid_argument[typeinfo for std::invalid_argument]+0x8): undefined reference to `typeinfo for std::logic_error'
/tmp/cc8DNmKI.o:(.rodata._ZTISt12domain_error[typeinfo for std::domain_error]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
/tmp/cc8DNmKI.o:(.rodata._ZTISt12domain_error[typeinfo for std::domain_error]+0x8): undefined reference to `typeinfo for std::logic_error'
/tmp/cc8DNmKI.o:(.eh_frame+0xeb): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
and even more....
Judging from undefined reference to __gxx_personality_v0 linker message it looks like you are linking with gcc. You need to link C++ applications with g++. Or link with gcc and add -lstdc++ to the linker command line.
You aren't showing the relevant code and compiler invocation, but know that std::exception has an unimplemented virtual member function what() that you're expected to override, so don't go throwing naked std::exceptions if you want to callwhat().
Any of the derived, specific exceptions in <stdexcept> will implement what() and allow you to store a message when you're constructing the exception object.