PDA

Ver la Versión Completa : Usar las librerias Boost en C++Builder 2010


aguml
02-05-2020, 13:55:15
Bueno amigos, lo primero es que no se como instalarlas asi que me bajé las librerías y fui al directorio "C:\Program Files (x86)\Embarcadero\RAD Studio\7.0\include\" y ya había un directorio llamado "boost_1_34" asi que la sustituí por la de boost_1_73 y cambié la clave de las environment paths para que apunte a esta en vez de a la anterior (solo le cambié el 34 por 73 y el resto quedo igual que estaba). Luego he intentado compilar el ejemplo siguiente que viene en la misma libreria:
#include <boost\crc.hpp>
#include <string>
#include <iostream>

int main()
{
std::string str( "The quick brown fox jumps over the lazy dog" );
boost::crc_32_type crc;
crc.process_bytes( str.data(), str.size() );

std::cout << "Checksum: " << std::hex << crc.checksum() << std::endl;
return 0;
}
//---------------------------------------------------------------------------

y ahí empiezan los problemas:
Checking project dependencies...
Compiling Project1.cbproj (Debug configuration)
[BCC32 Error] File1.cpp(3): E2209 Unable to open include file 'boost\crc.hpp'
[BCC32 Error] iosfwd(254): E2238 Multiple declaration for 'char_traits<wchar_t>::int_type'
[BCC32 Error] iosfwd(136): E2344 Earlier declaration of 'char_traits<wchar_t>::int_type'
[BCC32 Error] iosfwd(260): E2238 Multiple declaration for 'char_traits<wchar_t>::assign(wchar_t &,const wchar_t &)'
[BCC32 Error] iosfwd(141): E2344 Earlier declaration of 'char_traits<wchar_t>::assign(wchar_t &,const wchar_t &)'
[BCC32 Error] iosfwd(265): E2238 Multiple declaration for 'char_traits<wchar_t>::eq(const wchar_t &,const wchar_t &)'
[BCC32 Error] iosfwd(146): E2344 Earlier declaration of 'char_traits<wchar_t>::eq(const wchar_t &,const wchar_t &)'
[BCC32 Error] iosfwd(270): E2238 Multiple declaration for 'char_traits<wchar_t>::lt(const wchar_t &,const wchar_t &)'
[BCC32 Error] iosfwd(151): E2344 Earlier declaration of 'char_traits<wchar_t>::lt(const wchar_t &,const wchar_t &)'
[BCC32 Error] iosfwd(276): E2238 Multiple declaration for 'char_traits<wchar_t>::compare(const wchar_t *,const wchar_t *,unsigned int)'
[BCC32 Error] iosfwd(156): E2344 Earlier declaration of 'char_traits<wchar_t>::compare(const wchar_t *,const wchar_t *,unsigned int)'
[BCC32 Error] iosfwd(283): E2238 Multiple declaration for 'char_traits<wchar_t>::length(const wchar_t *)'
[BCC32 Error] iosfwd(167): E2344 Earlier declaration of 'char_traits<wchar_t>::length(const wchar_t *)'
[BCC32 Error] iosfwd(290): E2238 Multiple declaration for 'char_traits<wchar_t>::copy(wchar_t *,const wchar_t *,unsigned int)'
[BCC32 Error] iosfwd(176): E2344 Earlier declaration of 'char_traits<wchar_t>::copy(wchar_t *,const wchar_t *,unsigned int)'
[BCC32 Error] iosfwd(298): E2238 Multiple declaration for 'char_traits<wchar_t>::find(const wchar_t *,unsigned int,const wchar_t &)'
[BCC32 Error] iosfwd(187): E2344 Earlier declaration of 'char_traits<wchar_t>::find(const wchar_t *,unsigned int,const wchar_t &)'
[BCC32 Error] iosfwd(305): E2238 Multiple declaration for 'char_traits<wchar_t>::move(wchar_t *,const wchar_t *,unsigned int)'
[BCC32 Error] iosfwd(197): E2344 Earlier declaration of 'char_traits<wchar_t>::move(wchar_t *,const wchar_t *,unsigned int)'
[BCC32 Error] iosfwd(312): E2238 Multiple declaration for 'char_traits<wchar_t>::assign(wchar_t *,unsigned int,wchar_t)'
[BCC32 Error] iosfwd(212): E2344 Earlier declaration of 'char_traits<wchar_t>::assign(wchar_t *,unsigned int,wchar_t)'
[BCC32 Error] iosfwd(323): E2238 Multiple declaration for 'char_traits<wchar_t>::to_int_type(const wchar_t &)'
[BCC32 Error] iosfwd(227): E2344 Earlier declaration of 'char_traits<wchar_t>::to_int_type(const wchar_t &)'
[BCC32 Error] iosfwd(334): E2238 Multiple declaration for 'char_traits<wchar_t>::eof()'
[BCC32 Error] iosfwd(238): E2344 Earlier declaration of 'char_traits<wchar_t>::eof()'
[BCC32 Error] iosfwd(355): E2238 Multiple declaration for 'char_traits<char>::assign(char &,const char &)'
[BCC32 Error] iosfwd(141): E2344 Earlier declaration of 'char_traits<char>::assign(char &,const char &)'
[BCC32 Error] iosfwd(360): E2238 Multiple declaration for 'char_traits<char>::eq(const char &,const char &)'
[BCC32 Error] iosfwd(146): E2344 Earlier declaration of 'char_traits<char>::eq(const char &,const char &)'
[BCC32 Error] iosfwd(365): E2238 Multiple declaration for 'char_traits<char>::lt(const char &,const char &)'
[BCC32 Error] iosfwd(151): E2344 Earlier declaration of 'char_traits<char>::lt(const char &,const char &)'
[BCC32 Error] iosfwd(371): E2238 Multiple declaration for 'char_traits<char>::compare(const char *,const char *,unsigned int)'
[BCC32 Error] iosfwd(156): E2344 Earlier declaration of 'char_traits<char>::compare(const char *,const char *,unsigned int)'
[BCC32 Error] iosfwd(378): E2238 Multiple declaration for 'char_traits<char>::length(const char *)'
[BCC32 Error] iosfwd(167): E2344 Earlier declaration of 'char_traits<char>::length(const char *)'
[BCC32 Error] iosfwd(385): E2238 Multiple declaration for 'char_traits<char>::copy(char *,const char *,unsigned int)'
[BCC32 Error] iosfwd(176): E2344 Earlier declaration of 'char_traits<char>::copy(char *,const char *,unsigned int)'
[BCC32 Error] iosfwd(393): E2238 Multiple declaration for 'char_traits<char>::find(const char *,unsigned int,const char &)'
[BCC32 Error] iosfwd(187): E2344 Earlier declaration of 'char_traits<char>::find(const char *,unsigned int,const char &)'
[BCC32 Error] iosfwd(400): E2238 Multiple declaration for 'char_traits<char>::move(char *,const char *,unsigned int)'
[BCC32 Error] iosfwd(197): E2344 Earlier declaration of 'char_traits<char>::move(char *,const char *,unsigned int)'
[BCC32 Error] iosfwd(407): E2238 Multiple declaration for 'char_traits<char>::assign(char *,unsigned int,char)'
[BCC32 Error] iosfwd(212): E2344 Earlier declaration of 'char_traits<char>::assign(char *,unsigned int,char)'
[BCC32 Error] iosfwd(418): E2238 Multiple declaration for 'char_traits<char>::to_int_type(const char &)'
[BCC32 Error] iosfwd(227): E2344 Earlier declaration of 'char_traits<char>::to_int_type(const char &)'
[BCC32 Error] iosfwd(429): E2238 Multiple declaration for 'char_traits<char>::eof()'
[BCC32 Error] iosfwd(238): E2344 Earlier declaration of 'char_traits<char>::eof()'
[BCC32 Error] xutility(345): E2406 Dependent type qualifier 'bool' is not a class or struct type
[BCC32 Error] xutility(346): E2406 Dependent type qualifier 'bool' is not a class or struct type
[BCC32 Error] xutility(347): E2406 Dependent type qualifier 'bool' is not a class or struct type
[BCC32 Error] xutility(347): E2228 Too many error or warning messages
Failed
Elapsed time: 00:00:00.2

Así tengo la variable de entorno:
Variable name: CG_BOOST_ROOT
Variable value: C:\Program Files (x86)\Embarcadero\RAD Studio\7.0\include\boost_1_73
No se que hacer :(
Gracias por adelantado.

aguml
02-05-2020, 14:18:07
Vale, he añadido "$(BDS)\include\boost_1_73" a Include Path y a Library Path y parece que ya lo reconoce pero ahora me da otros errores relacionados con los archivos de esa librería:
En la linea:
#define WCHAR_MAX UINT16_MAX
[BCC32 Warning] stdint.h(168): W8017 Redefinition of 'WCHAR_MAX' is not identical

Otro:
bool const integral_constant<bool, val>::value;
[BCC32 Error] integral_constant.hpp(90): E2316 'value' is not a member of 'integral_constant<bool,val>'

Otro:
enum { static_size = N };
[BCC32 Error] array.hpp(155): E2324 Numeric constant too large

Otro:
boost::array<unsigned char, ( UINTMAX_C(1) << CHAR_BIT )> result;
[BCC32 Error] crc.hpp(411): E2450 Undefined structure 'array<unsigned char,256>
[BCC32 Error] crc.hpp(411): E2449 Size of 'result' is unknown or zero'

Otro:
static boost::array<unsigned char, ( UINTMAX_C(1) << CHAR_BIT )> const
table = make_byte_reflection_table();
[BCC32 Error] crc.hpp(438): E2450 Undefined structure 'array<unsigned char,256>'

No encuentro por internet como solucionar todos estos fallos :confused:

aguml
02-05-2020, 16:08:02
Bueno, por lo visto tiene que ser alguna incompatibilidad con la ultima versión porque el mismo código funciona perfectamente en la que ya tenia.
Ahora tengo una duda, viendo códigos de otros usuarios he conseguido armarme esto:

#include <vcl.h>
#include <boost\crc.hpp>
#include <iostream>
#include <fstream>
#pragma hdrstop

//---------------------------------------------------------------------------

#pragma argsused

uint32_t crc32(std::istream &is)
{
char buf[4096];
boost::crc_32_type result;

do {
is.read(buf, sizeof buf);
result.process_bytes(buf, is.gcount());
} while (is);

if (is.eof()) {
return result.checksum();
} else {
throw std::runtime_error("File read failed");
}
}
//---------------------------------------------------------------------------

int _tmain(int argc, _TCHAR* argv[])
{
ifstream myfile;
myfile.open("mi_archivo.bin", ios::in | ios::app | ios::binary);
uint32_t crc=crc32(myfile);
myfile.close();
std::cout << crc << std::endl;
std::getchar();

return 0;
}
La cosa es que no será una aplicacion de consola donde quiero usarlo y a ser posible evitar añadir las librerias de C++ y usar las de C++Builder y no se como sustituir fstream e iostream para usar las propias de C++builder. ¿podeis ayudarme con eso?

escafandra
04-05-2020, 13:53:55
Puedes usar stream de la VLC (TFileStream) o leer el archivo sobre un buffer con _lread((int)hFile, Buffer, Size) que forma parte de las dll de Windows.

Saludos.