I am using htmlcxx library for a simple program but I got stuck in a problem, I searched many other related solutions but my problem is still a problem, Hope any one can help me, Here is the code I used in Kdevelop on Ubuntu:
#include <iostream>
#include <string>
#include <htmlcxx/html/ParserDom.h>
using namespace htmlcxx;
int main()
{
//Parse some html code
std::string html = "<html><body>hey</body></html>";
HTML::ParserDom parser;
tree<HTML::Node> dom= parser.parseTree(html) ;
//Print whole DOM tree
std::cout << dom << std::endl;
//Dump all links in the tree
tree<HTML::Node>::iterator it = dom.begin();
tree<HTML::Node>::iterator end = dom.end();
for (; it != end; ++it)
{
if (it->tagName() == "A")
{
it->parseAttributes();
std::cout << it->attribute("href").second;
}
}
//Dump all text of the document
it = dom.begin();
end = dom.end();
for (; it != end; ++it)
{
if ((!it->isTag()) && (!it->isComment()))
{
std::cout << it->text();
}
}
return 0;
}
And here is the error come when I build it in Kdevelop:
/home/ratior/projects/html/build> make -j2
Scanning dependencies of target html
[100%] Building CXX object CMakeFiles/html.dir/main.o
Linking CXX executable html
CMakeFiles/html.dir/main.o: In function `main':
/home/ratior/projects/html/main.cpp:17: undefined reference to `htmlcxx::HTML::ParserDom::parseTree(std::string const&)'
/home/ratior/projects/html/main.cpp:20: undefined reference to `htmlcxx::HTML::operator<<(std::ostream&, tree<htmlcxx::HTML::Node, std::allocator<tree_node_<htmlcxx::HTML::Node> > > const&)'
/home/ratior/projects/html/main.cpp:29: undefined reference to `htmlcxx::HTML::Node::parseAttributes()'
CMakeFiles/html.dir/main.o: In function `htmlcxx::HTML::ParserDom::ParserDom()':
/usr/local/include/htmlcxx/html/ParserDom.h:14: undefined reference to `vtable for htmlcxx::HTML::ParserDom'
CMakeFiles/html.dir/main.o: In function `htmlcxx::HTML::ParserDom::~ParserDom()':
/usr/local/include/htmlcxx/html/ParserDom.h:15: undefined reference to `vtable for htmlcxx::HTML::ParserDom'
collect2: error: ld returned 1 exit status
make[2]: *** [html] Error 1
make[1]: *** [CMakeFiles/html.dir/all] Error 2
make: *** [all] Error 2
*** Failure: Exit code 2 **strong text**
Wrong path to the library is the reason why it's not linking the code.
Related
I use boost.log for my project.
But when I tried to set filter for sinks, compilation errors came.
code are simple:
BOOST_LOG_ATTRIBUTE_KEYWORD(MyTag, "My_Tag", std::string);
BOOST_LOG_INLINE_GLOBAL_LOGGER_CTOR_ARGS(
my_logger
, boost::log::sources::channel_logger_mt< >
, (boost::log::keywords::channel = "default"))
typedef boost::log::sinks::synchronous_sink<
boost::log::sinks::text_ostream_backend > TextSink;
boost::shared_ptr< TextSink > logSink = boost::make_shared< TextSink >();
auto backSink = boost::make_shared<std::ofstream>("default.log");
!!! compilation error, no add_attribute in channel_logger !!!
my_logger::get().add_attribute("My_Tag"
, boost::log::attributes::constant<String>("My_Tag"));
logSink->set_filter(
boost::log::expressions::has_attr(MyTag)
!!! compilation error, invalid operand expression between attribute_actor and std::string !!!
&& boost::log::expressions::attr<std::string>("My_Tag")==std::string("My_Tag")
!!! compilation error, invalid operand expression between attribute_keyword<tag::MyTag> and char[7] !!!
&& MyTag=="My_Tag"
I also tried to define filter function, but got following error:
bool my_filter(
boost::log::value_ref< std::string
!!! compilation error, no tag_attr in boost::log::expressions::tag !!!
, boost::log::expressions::tag::tag_attr > const& tag)
{
return level >= warning || tag == "IMPORTANT_MESSAGE";
}
By the way, I also have following error, but this error will disappear if all other compilation errors were solved.
!!! no open_record in severity_logger_mt !!!
BOOST_LOG_SEV(slg, normal) << "A regular message";
could anyone help me?
full code :
#include <boost/phoenix/operator.hpp>
#include <boost/log/sources/channel_logger.hpp>
#include <boost/log/attributes.hpp>
#include <boost/log/attributes/attribute.hpp>
#include <boost/log/attributes/attribute_cast.hpp>
#include <boost/log/keywords/filter.hpp>
#include <boost/log/expressions/predicates.hpp>
#include <boost/log/expressions/attr_fwd.hpp>
#include <boost/log/expressions/attr.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/sinks.hpp>
BOOST_LOG_INLINE_GLOBAL_LOGGER_CTOR_ARGS(
my_channel_logger
, boost::log::sources::channel_logger_mt< >
, (boost::log::keywords::channel = "channel"))
BOOST_LOG_ATTRIBUTE_KEYWORD(MyTag, "My_Tag", std::string);
typedef boost::log::sinks::synchronous_sink<
boost::log::sinks::text_ostream_backend > TextSink;
static boost::shared_ptr< TextSink > logSink = boost::make_shared< TextSink >();
static auto backSink = boost::make_shared<std::ofstream>("output.log");
void func() {
!!! compilation error, no 'open_record' in channel_logger_mt !!!
BOOST_LOG_CHANNEL(my_channel_logger::get(), "channel")<<"channel log";
!!! compilation error, no add_attribute in channel_logger !!!
my_channel_logger::get().add_attribute("My_Tag"
, boost::log::attributes::constant<String>("My_Tag"));
}
compilation error for no open_record in channel_logger_mt:
***.cpp:87:5: error: no member named 'open_record' in 'boost::log::v2_mt_nt6::sources::channel_logger_mt<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >'
channel_feature.hpp:236:41: note: expanded from macro 'BOOST_LOG_CHANNEL'
channel_feature.hpp:231:5: note: expanded from macro 'BOOST_LOG_STREAM_CHANNEL'
record_ostream.hpp:566:5: note: expanded from macro 'BOOST_LOG_STREAM_WITH_PARAMS'
record_ostream.hpp:555:50: note: expanded from macro 'BOOST_LOG_STREAM_WITH_PARAMS_INTERNAL'
compilation error for no add_attribute in channel_logger_mt:
***.cpp:76:31: error: no member named 'add_attribute' in 'boost::log::v2_mt_nt6::sources::channel_logger_mt<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >'
Most likely, you're missing #includes in your code.
!!! compilation error, no add_attribute in channel_logger !!!
my_logger::get().add_attribute("My_Tag"
, boost::log::attributes::constant<String>("My_Tag"));
add_attribute is defined by basic_composite_logger, from which channel_logger_mt derives. You need to include boost/log/sources/channel_logger.hpp.
!!! compilation error, invalid operand expression between attribute_actor and std::string !!!
&& boost::log::expressions::attr<std::string>("My_Tag")==std::string("My_Tag")
!!! compilation error, invalid operand expression between attribute_keyword<tag::MyTag> and char[7] !!!
&& MyTag=="My_Tag"
Most likely, you're missing an include of boost/phoenix/operator.hpp. Or you can include boost/log/expressions.hpp, which automatically includes it for you.
!!! no open_record in severity_logger_mt !!!
BOOST_LOG_SEV(slg, normal) << "A regular message";
Same as with channel_logger_mt. You need to include boost/log/sources/severity_logger.hpp.
Note that for every component in the docs, there is a list of associated Boost.Log headers in the very beginning of the section. Here is an example for the severity logger.
Update on 2019-07-03:
Your full code compiles, if the following includes are added:
#include <string>
#include <fstream>
#include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/smart_ptr/make_shared_object.hpp>
#include <boost/log/sources/global_logger_storage.hpp>
#include <boost/log/sources/record_ostream.hpp>
I also had to remove the "!!!" lines and use std::string instead of String in the constant attribute.
In general, you have to include a header for every component you use in your code.
I want to be able to get the stream-id which is associated with an execution policy in thrust. I am trying to access this function.
I have tried this :
cudaStream_t stream = 0;
auto policy = thrust::cuda::par.on(stream);
cudaStream_t str = stream(policy);
but I am getting a compilation error :
stream.cu(7): error: expression preceding parentheses of apparent call must have (pointer-to-) function type
Could I get some ideas on how to do this?
"I am trying to access this function." Trying to directly use e.g. things in detail are part of the implementation and may change from one version to the next. To wit: the file you are referring to does not even exist in the the current thrust distributed with CUDA 10.
However, this seems to work for me:
$ cat t354.cu
#include <thrust/execution_policy.h>
#include <iostream>
#include <cstring>
int main(){
cudaStream_t mystream;
cudaStreamCreate(&mystream);
auto policy = thrust::cuda::par.on(mystream);
cudaStream_t str = stream(policy);
for (int i = 0; i < sizeof(cudaStream_t); i++)
if ( *(reinterpret_cast<unsigned char *>(&mystream)+i) != *(reinterpret_cast<unsigned char *>(&str)+i)) {std::cout << "mismatch" << std::endl; return -1;}
std::cout << "match" << std::endl;
}
$ nvcc -std=c++11 -o t354 t354.cu
$ cuda-memcheck ./t354
========= CUDA-MEMCHECK
match
========= ERROR SUMMARY: 0 errors
$
when I construct a string
string s ="";
s = rb.rep + a.chemin.substr(rep.size());
//cout << "s:" << s << endl;
if (s.empty()){
cerr<<"c++ string is uninitialized"<<endl;
exit(1);
}
and doing
if(is_file(s)){
a.s="ok";
}
else{
SEULS.push_back(ela.first);
a.s="SEUL";
}
with this function:
bool is_file(string &path) {
the structure is defined
struct stat buf;
stat(path.c_str(), &buf);
you know if it is a file or not
if(S_ISREG(buf.st_mode)) cout<<"is_file "<<path<<" "<<S_ISREG(buf.st_mode)<<endl;
else cout<<"NO is_file "<<path<<" "<<S_ISREG(buf.st_mode)<<endl
another way is trying to open the file
FILE*f=fopen(path.c_str(), "r");
if( f == NULL){
cerr<<"PROB fopen "<<path<<endl;
exit (EXIT_FAILURE);
}
else{
fclose(f);
}
the result is returned
return S_ISREG(buf.st_mode);
}
I got this result on console
is_file e/rep_A/1.txt 1
NO is_file e/2.txt 0
PROB fopen e/2.txt
Program ended with exit code: 1
but when I comment
// FILE*f=fopen(path.c_str(), "r");
// if( f == NULL){
// cerr<<"PROB fopen "<<path<<endl;
// exit (EXIT_FAILURE);
// }
// else{
// fclose(f);
// }
I got
is_file e/2.txt 1
is_file e/rep_B/3.txt 1
lesSeuls de e et de a...
is_file a/rep_A/1.txt 1
is_file a/rep_B/3.txt 1
PROBLEM:
e/2.txt doesn't exists !!
and if I uncomment
cout << "s:" << s << endl;
before calling
if(is_file(s)){
a.s="ok";
}
else{
That's ok !
I get
NO is_file e/2.txt 0
PROB fopen e/2.txt
Program ended with exit code: 1
To result I have to print string s or printing something to get the good string s. it is like concurrent programming.
This is not a joke
Did you meet that?
Thanks
When the file doesn't exist, stat would fail (with ENOENT error), leaving its struct stat parameter unchanged. Your program does not check the return value of stat call; even if the call fails, the program cheerfully proceeds to examine random garbage left on the stack by previous functions.
That's why the behavior of the program changes depending on what you do before the stat call - you merely observe different sets of garbage.
I am implementing an example program with nvml library as shown at https://devtalk.nvidia.com/default/topic/504951/how-to-call-nvml-apis-/
The program is as follows:
#include <stdio.h>
#include <nvidia/gdk/nvml.h>
const char * convertToComputeModeString(nvmlComputeMode_t mode)
{
switch (mode)
{
case NVML_COMPUTEMODE_DEFAULT:
return "Default";
case NVML_COMPUTEMODE_EXCLUSIVE_THREAD:
return "Exclusive_Thread";
case NVML_COMPUTEMODE_PROHIBITED:
return "Prohibited";
case NVML_COMPUTEMODE_EXCLUSIVE_PROCESS:
return "Exclusive Process";
default:
return "Unknown";
}
}
int main()
{
nvmlReturn_t result;
unsigned int device_count, i;
// First initialize NVML library
result = nvmlInit();
if (NVML_SUCCESS != result)
{
printf("Failed to initialize NVML: %s\n", nvmlErrorString(result));
printf("Press ENTER to continue...\n");
getchar();
return 1;
}
result = nvmlDeviceGetCount(&device_count);
if (NVML_SUCCESS != result)
{
printf("Failed to query device count: %s\n", nvmlErrorString(result));
goto Error;
}
printf("Found %d device%s\n\n", device_count, device_count != 1 ? "s" : "");
printf("Listing devices:\n");
for (i = 0; i < device_count; i++)
{
nvmlDevice_t device;
char name[64];
nvmlPciInfo_t pci;
nvmlComputeMode_t compute_mode;
// Query for device handle to perform operations on a device
// You can also query device handle by other features like:
// nvmlDeviceGetHandleBySerial
// nvmlDeviceGetHandleByPciBusId
result = nvmlDeviceGetHandleByIndex(i, &device);
if (NVML_SUCCESS != result)
{
printf("Failed to get handle for device %i: %s\n", i, nvmlErrorString(result));
goto Error;
}
result = nvmlDeviceGetName(device, name, sizeof(name)/sizeof(name[0]));
if (NVML_SUCCESS != result)
{
printf("Failed to get name of device %i: %s\n", i, nvmlErrorString(result));
goto Error;
}
// pci.busId is very useful to know which device physically you're talking to
// Using PCI identifier you can also match nvmlDevice handle to CUDA device.
result = nvmlDeviceGetPciInfo(device, &pci);
if (NVML_SUCCESS != result)
{
printf("Failed to get pci info for device %i: %s\n", i, nvmlErrorString(result));
goto Error;
}
printf("%d. %s [%s]\n", i, name, pci.busId);
// This is a simple example on how you can modify GPU's state
result = nvmlDeviceGetComputeMode(device, &compute_mode);
if (NVML_ERROR_NOT_SUPPORTED == result)
printf("\t This is not CUDA capable device\n");
else if (NVML_SUCCESS != result)
{
printf("Failed to get compute mode for device %i: %s\n", i, nvmlErrorString(result));
goto Error;
}
else
{
// try to change compute mode
printf("\t Changing device's compute mode from '%s' to '%s'\n",
convertToComputeModeString(compute_mode),
convertToComputeModeString(NVML_COMPUTEMODE_PROHIBITED));
result = nvmlDeviceSetComputeMode(device, NVML_COMPUTEMODE_PROHIBITED);
if (NVML_ERROR_NO_PERMISSION == result)
printf("\t\t Need root privileges to do that: %s\n", nvmlErrorString(result));
else if (NVML_ERROR_NOT_SUPPORTED == result)
printf("\t\t Compute mode prohibited not supported. You might be running on\n"
"\t\t windows in WDDM driver model or on non-CUDA capable GPU.\n");
else if (NVML_SUCCESS != result)
{
printf("\t\t Failed to set compute mode for device %i: %s\n", i, nvmlErrorString(result));
goto Error;
}
else
{
printf("\t Restoring device's compute mode back to '%s'\n",
convertToComputeModeString(compute_mode));
result = nvmlDeviceSetComputeMode(device, compute_mode);
if (NVML_SUCCESS != result)
{
printf("\t\t Failed to restore compute mode for device %i: %s\n", i, nvmlErrorString(result));
goto Error;
}
}
}
}
result = nvmlShutdown();
if (NVML_SUCCESS != result)
printf("Failed to shutdown NVML: %s\n", nvmlErrorString(result));
printf("All done.\n");
printf("Press ENTER to continue...\n");
getchar();
return 0;
Error:
result = nvmlShutdown();
if (NVML_SUCCESS != result)
printf("Failed to shutdown NVML: %s\n", nvmlErrorString(result));
printf("Press ENTER to continue...\n");
getchar();
return 1;
}
makefile as follows:
ARCH := $(shell getconf LONG_BIT)
ifeq (${ARCH},32)
NVML_LIB := ../lib/
else ifeq (${ARCH},64)
NVML_LIB := /usr/lib/nvidia-340/
else
$(error Unknown architecture!)
endif
CFLAGS := -I ../inc
LDFLAGS := -lnvidia-ml -L $(NVML_LIB)
example: example.o
$(CC) $(LDFLAGS) $< -o $#
clean:
-#rm -f example.o
-#rm -f example
And the error I get is:
cc -lnvidia-ml -L /usr/src/gdk/nvml/lib/ example.o -o example
example.o: In function `main':
example.c:(.text+0x5f): undefined reference to `nvmlInit_v2'
example.c:(.text+0x7b): undefined reference to `nvmlErrorString'
example.c:(.text+0xb5): undefined reference to `nvmlDeviceGetCount_v2'
example.c:(.text+0xd1): undefined reference to `nvmlErrorString'
example.c:(.text+0x149): undefined reference to `nvmlDeviceGetHandleByIndex_v2'
example.c:(.text+0x165): undefined reference to `nvmlErrorString'
example.c:(.text+0x19f): undefined reference to `nvmlDeviceGetName'
example.c:(.text+0x1bb): undefined reference to `nvmlErrorString'
example.c:(.text+0x1f3): undefined reference to `nvmlDeviceGetPciInfo_v2'
example.c:(.text+0x20f): undefined reference to `nvmlErrorString'
example.c:(.text+0x269): undefined reference to `nvmlDeviceGetComputeMode'
example.c:(.text+0x29d): undefined reference to `nvmlErrorString'
example.c:(.text+0x2ff): undefined reference to `nvmlDeviceSetComputeMode'
example.c:(.text+0x31b): undefined reference to `nvmlErrorString'
example.c:(.text+0x360): undefined reference to `nvmlErrorString'
example.c:(.text+0x3b5): undefined reference to `nvmlDeviceSetComputeMode'
example.c:(.text+0x3d1): undefined reference to `nvmlErrorString'
example.c:(.text+0x40c): undefined reference to `nvmlShutdown'
example.c:(.text+0x428): undefined reference to `nvmlErrorString'
example.c:(.text+0x45f): undefined reference to `nvmlShutdown'
example.c:(.text+0x47b): undefined reference to `nvmlErrorString'
collect2: error: ld returned 1 exit status
make: *** [example] Error 1
pranjal#PCL:~/nvidia$ make
cc -lnvidia-ml -L /usr/lib/nvidia-340/ example.o -o example
example.o: In function `main':
example.c:(.text+0x5f): undefined reference to `nvmlInit_v2'
example.c:(.text+0x7b): undefined reference to `nvmlErrorString'
example.c:(.text+0xb5): undefined reference to `nvmlDeviceGetCount_v2'
example.c:(.text+0xd1): undefined reference to `nvmlErrorString'
example.c:(.text+0x149): undefined reference to `nvmlDeviceGetHandleByIndex_v2'
example.c:(.text+0x165): undefined reference to `nvmlErrorString'
example.c:(.text+0x19f): undefined reference to `nvmlDeviceGetName'
example.c:(.text+0x1bb): undefined reference to `nvmlErrorString'
example.c:(.text+0x1f3): undefined reference to `nvmlDeviceGetPciInfo_v2'
example.c:(.text+0x20f): undefined reference to `nvmlErrorString'
example.c:(.text+0x269): undefined reference to `nvmlDeviceGetComputeMode'
example.c:(.text+0x29d): undefined reference to `nvmlErrorString'
example.c:(.text+0x2ff): undefined reference to `nvmlDeviceSetComputeMode'
example.c:(.text+0x31b): undefined reference to `nvmlErrorString'
example.c:(.text+0x360): undefined reference to `nvmlErrorString'
example.c:(.text+0x3b5): undefined reference to `nvmlDeviceSetComputeMode'
example.c:(.text+0x3d1): undefined reference to `nvmlErrorString'
example.c:(.text+0x40c): undefined reference to `nvmlShutdown'
example.c:(.text+0x428): undefined reference to `nvmlErrorString'
example.c:(.text+0x45f): undefined reference to `nvmlShutdown'
example.c:(.text+0x47b): undefined reference to `nvmlErrorString'
collect2: error: ld returned 1 exit status
make: *** [example] Error 1
Any help would be appreciated. Thank you.
Here's what I did on a linux CUDA 7.5 setup:
Update the GPU driver to 352.79. In my case, this was done via the runfile installer here. If you have previously installed the GPU driver via the package manager method (e.g. .deb) then you don't want to use the runfile installer method.
get the latest version of the GDK (see note below), which at this time happens to target 352.79, and includes nvml:
wget --no-check-certificate http://developer.download.nvidia.com/compute/cuda/7.5/Prod/gdk/gdk_linux_amd64_352_79_release.run
install the GDK:
sh gdk_linux_amd64_352_79_release.run
verify that the appropriate libraries were updated:
ls /usr/lib64/libnv*
(and you should see libnvidia-ml.so.352.79 etc.)
compile the example file:
g++ -I./gdk352_79/usr/include -L/usr/lib64 -lnvidia-ml example.c -o example
When I run the example executable, I get:
$ ./example
Found 2 devices
Listing devices:
0. Quadro 5000 [0000:02:00.0]
Changing device's compute mode from 'Default' to 'Prohibited'
Need root privileges to do that: Insufficient Permissions
1. GeForce GT 640 [0000:03:00.0]
Changing device's compute mode from 'Default' to 'Prohibited'
Need root privileges to do that: Insufficient Permissions
All done.
Press ENTER to continue...
$
Hopefully this will get you going. I am assuming you don't need help making any Makefile changes if needed. If your Makefile is not working, keep modifying it until you get the exact compile command I list in step 5.
NOTE: As of CUDA 8.0, the GDK is not a separate entity but is installed with CUDA 8.0 toolkit. It should not be necessary to install the GDK separately.
I'm writing a web browser and trying to use regex_iterator to go through the tags of an HTML document and ultimately create a document tree. First I need a regular expression that will get me an HTML tag. The following should print out each HTML tag
#include <string>
#include <regex>
#include <iostream>
int main()
{
std::string s("<!DOCTYPE html><head></head><body><div class='container' id='someId'><p>Here's a p tag</p><p>Here's another p tag</p></div></body>");
std::regex e("[someRegularExpression]");
std::regex_iterator<std::string::iterator> htmlTagRover ( s.begin(), s.end(), e );
std::regex_iterator<std::string::iterator> offend;
while (htmlTagRover != offend)
std::cout << htmlTagRover->str() << std::endl;
return 0;
}
if [someRegularExpression] is equal to a regular expression for an HTML tag. Bur I'm getting the following error when I try to run the program:
/home/svzQOJ/ccEMKoqM.o: In function main':
prog.cpp:(.text.startup+0xd1): undefined reference tostd::regex_iterator<__gnu_cxx::__normal_iterator, char, std::regex_traits >::regex_iterator(__gnu_cxx::__normal_iterator, __gnu_cxx::__normal_iterator, std::basic_regex > const&, std::bitset<11u>)'
prog.cpp:(.text.startup+0xdc): undefined reference to std::regex_iterator<__gnu_cxx::__normal_iterator<char*, std::string>, char, std::regex_traits<char> >::regex_iterator()'
prog.cpp:(.text.startup+0x1af): undefined reference tostd::regex_iterator<__gnu_cxx::__normal_iterator, char, std::regex_traits >::operator!=(std::regex_iterator<__gnu_cxx::__normal_iterator, char, std::regex_traits > const&)'
prog.cpp:(.text.startup+0x1be): undefined reference to `std::regex_iterator<__gnu_cxx::__normal_iterator, char, std::regex_traits >::operator->()'
collect2: error: ld returned 1 exit status
Any idea why?
According to here, you don't need the <std::string::iterator> in your calls and you need to use the std::sregex_iterator (notice the s) to use regex with std::string.