小编Sas*_*cha的帖子

由Boost单元测试框架dll导出的std :: basic_ostringstream导致"已定义的符号" - 错误

我使用Visual Studio 2012.我的设置是这样的:

  • some.lib链接到some.exe
  • some.lib链接到some_test.exe

我在构建some_test.exe时使用BOOST_TEST_DYN_LINK.对于some.lib和test.exe,使用BOOST_ALL_DYN_LINK的结果是相同的.

我用/ MD(多线程DLL)构建了some_test.exe,some.exe和some.lib.我用runtime-link = shared构建了boost库.所有这些都是由VC11(Visual Studio 2012)构建和链接的.

问题是,在some.lib中,我想使用局部变量

std::ostringstream someStream;
Run Code Online (Sandbox Code Playgroud)

some.exe链接正常.但是当链接some_test.exe,它动态链接到boost单元测试框架(1.59)时,它给了我3个错误(LNK2005):

错误

boost_unit_test_framework-vc110-mt-1_59.lib(boost_unit_test_framework-vc110-mt-1_59.dll) : error LNK2005: "public: __cdecl std::basic_ostringstream<char,struct std::char_traits<char>,class std::allocator<char> >::basic_ostringstream<char,struct std::char_traits<char>,class std::allocator<char> >(int)" (??0?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@H@Z) already defined in some.lib(some.obj) 
boost_unit_test_framework-vc110-mt-1_59.lib(boost_unit_test_framework-vc110-mt-1_59.dll) : error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl std::basic_ostringstream<char,struct std::char_traits<char>,class std::allocator<char> >::str(void)const " (?str@?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@XZ) already defined in some.lib(some.obj) 
boost_unit_test_framework-vc110-mt-1_59.lib(boost_unit_test_framework-vc110-mt-1_59.dll) : error LNK2005: "public: void __cdecl std::basic_ostringstream<char,struct std::char_traits<char>,class std::allocator<char> >::`vbase destructor'(void)" (??_D?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAXXZ) already defined in some.lib(some.obj) 
some_test.exe : fatal error LNK1169: one or …
Run Code Online (Sandbox Code Playgroud)

c++ dll boost visual-c++

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

Seek 对使用 boost filtering_istreambuf 初始化的 std::istream 不起作用

我试图读取一个文件。它应该是内存映射的性能。我想使用 iostream 的 boost 过滤器链来轻松包含 zip、bzip2 和 gzip 解压缩。

我尝试采用Using boost::iostreams mapping_file_source and filtering_streambuf to decompress file 中提出的解决方案。

我的问题:当我尝试seek()直播时,出现异常:“无随机访问”。这很奇怪,因为从文档中我了解到我可以std::istream用作接口。

我想出了以下代码(也在 coliru 上):

#include <iostream>
#include <stdio.h>
#include <boost/iostreams/device/mapped_file.hpp>
#include <boost/iostreams/stream.hpp>
#include <boost/iostreams/filtering_streambuf.hpp>

// and later also include ...
//#include <boost/iostreams/filter/gzip.hpp>
//#include <boost/iostreams/filter/bzip2.hpp>

int main()
{
    namespace io = boost::iostreams;
    io::mapped_file_source inputDevice;                           // the device to read from (file)
    io::stream<io::mapped_file_source> mappedFileStream; // the memory mapped file stream    
    io::filtering_istreambuf filteredInputStream;                 // the source file …
Run Code Online (Sandbox Code Playgroud)

c++ boost

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

在Visual Studio 2012 Express中设置C++调试环境

我需要调试的应用程序需要设置环境变量.这在Visual Studio 2012中看起来非常复杂.我想做类似的事情:

set path=c:\foo;c:\bar;c:\windows;c:\program files\application
set port=12345
set server=hulligulli
Run Code Online (Sandbox Code Playgroud)

微软告诉我,我应该"使用标准的环境变量语法".所以我希望我可以打开配置属性/调试/环境并编写

set path=c:\foo;c:\bar;c:\windows;c:\program files\application
set port=12345
set server=hulligulli
Run Code Online (Sandbox Code Playgroud)

要么:

path=c:\foo;c:\bar;c:\windows;c:\program files\application
port=12345
server=hulligulli
Run Code Online (Sandbox Code Playgroud)

但这两种变体都不起作用.鞋面根本没有设置路径.在较低版本中,Visual Studio会在每个空格中分割条目,因此上面的三行成为下面的四行:

path=c:\foo;c:\bar;c:\windows;c:\program
files\application
port=12345
server=hulligulli
Run Code Online (Sandbox Code Playgroud)

下面这两个变体可以防止分裂,但它们也会阻止路径正确格式化.即 应用程序将无法在路径中找到文件:

path=c:\foo;c:\bar;c:\windows;"c:\program files\application"
path="c:\foo;c:\bar;c:\windows;c:\program files\application"
Run Code Online (Sandbox Code Playgroud)

通过将所有内容复制到没有空格的路径来解决路径空间问题后,我发现,实际上只使用了环境的第一行.即 端口和服务器未设置.

path=c:\foo;c:\bar;c:\windows;c:\alternative_path\application
port=12345
server=hulligulli
Run Code Online (Sandbox Code Playgroud)

如何在Visual Studio调试环境中设置多个环境变量?

额外问题:如何在Visual Studio调试环境中使用标准路径条目(带空格)?

c++ visual-studio visual-studio-2012

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

标签 统计

c++ ×3

boost ×2

dll ×1

visual-c++ ×1

visual-studio ×1

visual-studio-2012 ×1