小编use*_*431的帖子

boost 1.58 未定义参考

我有一个项目已经编译和链接了几个月,没有出现任何问题。最近将 ubuntu 升级到 15.10,将 boost 版本从 1.55 提升到 1.58。现在突然间我收到了未定义的参考错误。无论我使用静态链接还是动态链接,我都会收到错误:

动态的:

> g++ -L"/home/peter/workspace/icflib/Debug" -pthread -o "icfapp" 
> ./src/AdminModule.o ./src/CaptureModule.o ./src/FFTModule.o
> ./src/GPSModule.o ./src/ReportModule.o ./src/icfapp.o   -licflib
> -lboost_program_options -lboost_date_time -lboost_filesystem -lboost_system -lfftw3 -lmysqlcppconn -lmysqlclient  ./src/FFTModule.o: In function
> `boost::filesystem::path::path<boost::filesystem::directory_entry>(boost::filesystem::directory_entry
> const&,
> boost::enable_if<boost::filesystem::path_traits::is_pathable<boost::decay<boost::filesystem::directory_entry>::type>,
> void>::type*)':   /usr/include/boost/filesystem/path.hpp:140: undefined
> reference to
> `boost::filesystem::path_traits::dispatch(boost::filesystem::directory_entry
> const&, std::string&)'    ./src/icfapp.o: In function
> `processCommandLine(int, char**)':
>   /home/peter/workspace/icfapp/Debug/../src/icfapp.cpp:85: undefined
> reference to
> `boost::program_options::options_description::options_description(std::string
> const&, unsigned int, unsigned int)'  ./src/icfapp.o: In function
> `boost::program_options::validation_error::validation_error(boost::program_options::validation_error::kind_t,
> …
Run Code Online (Sandbox Code Playgroud)

c++ boost

2
推荐指数
1
解决办法
3634
查看次数

如何重置std :: condition_variable

我试图使用条件变量触发第二个线程在一定数量的缓冲区处于双端队列中后做一些工作.

  • main()在紧密且时间敏感的循环中读取ADC数据
  • main()将缓冲区添加到双端队列(由线程池管理器处理)
  • deque深度是可变的,所以在main()中测试深度> = 4,然后调用notify_one是不可能的(即:在重处理时间,双端队列的深度可能高达200或300缓冲区或少至光处理时4)
  • thrd()永远不需要发信号main()

我的问题是在thrd()中,在获得信号和缓冲区<4之后,它会循环回到while循环并立即再次获得条件.有没有办法重置简历?

deque<int> vbufs;
std::mutex thrdLock;
void thrd()
{
    while (true) {
        cout << "thrd() waiting for lock\n";
        std::unique_lock < std::mutex > lock(thrdLock);
        cout << "thrd() waiting for condition\n";
        cv.wait(lock, []{ return (vbufs.size() > 0); });
        thrdLock.unlock();
        cout << "thrd() condition set\n";

        if (vbufs.size() >= 4) {    // pretend to do something with 4 buffers and remove them
            std::lock_guard < std::mutex > lock(thrdLock);
            vbufs.pop_front();
            vbufs.pop_front();
            vbufs.pop_front();
            vbufs.pop_front();
            cout << "thrd() reducing buffers:" << vbufs.size() …
Run Code Online (Sandbox Code Playgroud)

c++ multithreading thread-safety

1
推荐指数
1
解决办法
1708
查看次数

为什么将 int 分配给 std::map&lt;string,string&gt; 不会产生编译器错误

尝试将 int 分配给字符串\n std::string s = 5;\n会产生以下编译器错误:

\n

error: conversion from \xe2\x80\x98int\xe2\x80\x99 to non-scalar type \xe2\x80\x98std::string\xe2\x80\x99 {aka \xe2\x80\x98std::__cxx11::basic_string<char>\xe2\x80\x99} requested

\n

但是,将 int 分配给映射中的字符串值则不然。例如,下面的代码可以编译,更糟糕的是使赋值将 int 转换为 char

\n
map <string, string>m;\nm["test"] = 5;\n
Run Code Online (Sandbox Code Playgroud)\n

这不应该是一个错误吗?

\n

c++ initialization stdstring variable-assignment

1
推荐指数
1
解决办法
84
查看次数