Linking boost::locale with Embarcadero Berlin 10.1 - c++

I've created a simple console application in Embarcadero Berlin 10.1, selected 32 bit clang compiler, and copied in some code from here in the boost docs.
Here is the full code
#pragma hdrstop
#pragma argsused
#ifdef _WIN32
#include <tchar.h>
#else
typedef char _TCHAR;
#define _tmain main
#endif
#include <stdio.h>
#include <boost/locale.hpp>
int _tmain(int argc, _TCHAR* argv[])
{
using namespace boost::locale;
using namespace std;
generator gen;
locale loc=gen("");
// Create system default locale
locale::global(loc);
// Make it system global
cout.imbue(loc);
// Set as default locale for output
cout <<format("Today {1,date} at {1,time} we had run our first localization example") % time(0)
<<endl;
cout<<"This is how we show numbers in this locale "<<as::number << 103.34 <<endl;
cout<<"This is how we show currency in this locale "<<as::currency << 103.34 <<endl;
cout<<"This is typical date in the locale "<<as::date << std::time(0) <<endl;
cout<<"This is typical time in the locale "<<as::time << std::time(0) <<endl;
cout<<"This is upper case "<<to_upper("Hello World!")<<endl;
cout<<"This is lower case "<<to_lower("Hello World!")<<endl;
cout<<"This is title case "<<to_title("Hello World!")<<endl;
cout<<"This is fold case "<<fold_case("Hello World!")<<endl;
return 0;
}
But I get some linker errors:
[ilink32 Error] Error: Unresolved external 'boost::system::generic_category()' referenced from C:\PROGRAM FILES (X86)\EMBARCADERO\STUDIO\18.0\LIB\WIN32C\RELEASE\LIBBOOST_LOCALE-BCB32C-MT-SD-1_55.LIB|generator
[ilink32 Error] Error: Unresolved external 'boost::system::system_category()' referenced from C:\PROGRAM FILES (X86)\EMBARCADERO\STUDIO\18.0\LIB\WIN32C\RELEASE\LIBBOOST_LOCALE-BCB32C-MT-SD-1_55.LIB|generator
[ilink32 Error] Error: Unresolved external 'boost::locale::impl_win::create_convert(std::locale&, boost::locale::impl_win::winlocale&, unsigned int)' referenced from C:\PROGRAM FILES (X86)\EMBARCADERO\STUDIO\18.0\LIB\WIN32C\RELEASE\LIBBOOST_LOCALE-BCB32C-MT-SD-1_55.LIB|win_backend
[ilink32 Error] Error: Unresolved external 'boost::locale::impl_win::create_collate(std::locale&, boost::locale::impl_win::winlocale&, unsigned int)' referenced from C:\PROGRAM FILES (X86)\EMBARCADERO\STUDIO\18.0\LIB\WIN32C\RELEASE\LIBBOOST_LOCALE-BCB32C-MT-SD-1_55.LIB|win_backend
[ilink32 Error] Error: Unresolved external 'boost::locale::impl_win::create_formatting(std::locale&, boost::locale::impl_win::winlocale&, unsigned int)' referenced from C:\PROGRAM FILES (X86)\EMBARCADERO\STUDIO\18.0\LIB\WIN32C\RELEASE\LIBBOOST_LOCALE-BCB32C-MT-SD-1_55.LIB|win_backend
[ilink32 Error] Error: Unresolved external 'boost::locale::impl_win::create_parsing(std::locale&, boost::locale::impl_win::winlocale&, unsigned int)' referenced from C:\PROGRAM FILES (X86)\EMBARCADERO\STUDIO\18.0\LIB\WIN32C\RELEASE\LIBBOOST_LOCALE-BCB32C-MT-SD-1_55.LIB|win_backend
The first two I can fix by manually adding libboost_locale-bcb32c-MT-SD-1_55.lib to the project, it's my understanding and experience with boost that it shouldn't really need manually linking, but I don't mind this. The last 4 however, I'm not sure about at all. It looks to be related to the locale backend (Is it not ICU with Embarcadero supplied boost?)
Does anyone have any advice?

Your problem is very interesting to me. So I created a new project and copied your code into it and sure enough the problem repeated itself.After doing some research the only way I was able to overcome this issue was by adding collate.cpp and converter.cpp and numeric.cpp located in $(BDSINCLUDE)\boost_1_55\libs\locale\src\win32 into my project.
I also had to add #pragma link "libboost_system-bcb32c-mt-sd-1_55.lib" into my source code before the main function.
Sam

Related

LLVM: linking errors in VS 2015

I have downloaded source and built LLVM using CMake and VS 2015.
My sample program is the following:
#include <iostream>
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/CFG.h"
#include "llvm/IRReader/IRReader.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
int main(int argc, char **argv) {
if (argc < 2) {
errs() << "Usage: " << argv[0] << " <IR file>\n";
return 1;
}
// Parse the input LLVM IR file into a module.
SMDiagnostic Err;
LLVMContext TheContext;
std::unique_ptr<Module> Mod = parseIRFile(argv[1], Err, TheContext);
if (!Mod) {
Err.print(argv[0], errs());
return 1;
}
// ... use module
}
I get the following linking errors after having included the LLVM lib directory in the linker library path:
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "public: __thiscall llvm::LLVMContext::LLVMContext(void)" (??0LLVMContext#llvm##QAE#XZ) referenced in function _main LLVM_IRReader c:\Users\nlykkei\documents\visual studio 2015\Projects\LLVM_IRReader\LLVM_IRReader\Main.obj 1
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "public: __thiscall llvm::Module::~Module(void)" (??1Module#llvm##QAE#XZ) referenced in function "public: void * __thiscall llvm::Module::`scalar deleting destructor'(unsigned int)" (??_GModule#llvm##QAEPAXI#Z) LLVM_IRReader c:\Users\nlykkei\documents\visual studio 2015\Projects\LLVM_IRReader\LLVM_IRReader\Main.obj 1
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "class llvm::raw_ostream & __cdecl llvm::errs(void)" (?errs#llvm##YAAAVraw_ostream#1#XZ) referenced in function _main LLVM_IRReader c:\Users\nlykkei\documents\visual studio 2015\Projects\LLVM_IRReader\LLVM_IRReader\Main.obj 1
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "public: void __thiscall llvm::SMDiagnostic::print(char const *,class llvm::raw_ostream &,bool,bool)const " (?print#SMDiagnostic#llvm##QBEXPBDAAVraw_ostream#2#_N2#Z) referenced in function _main LLVM_IRReader c:\Users\nlykkei\documents\visual studio 2015\Projects\LLVM_IRReader\LLVM_IRReader\Main.obj 1
Does anyone know how to resolve these errors? I see, e.g., raw_ostream.obj in the LLVM build directory...
I've never used LLVM but based on your error messages, the linker didn't succeed in finding the LLVM class implementations.
To my point of view, including the LLVM lib directory is not enough. You have to include also the LLVM libraries (.lib which implement the LLVM classes) you want to link with.

Trivial Windows DLL built with GHC 64-bit does not link

For a proof-of-concept, I want to link some trivial Haskell code into my Visual C++ application (using Visual Studio 2013). Building with GHC 7.8.3 32-bit works, but building with GHC 7.8.4 64-bit does not (notice the slight discrepancy in GHC version too).
There are 3 files: Grep.hs and StartEnd.c are built with GHC to form a DLL. main.cpp is built with Visual Studio 2013 and attempts to link in the DLL library.
I am building the DLL from this:
> ghc -shared -O -optc-O -o Grep.dll StartEnd.c Grep.hs
And from within Visual Studio, I simply link against Grep.dll.a and include C:\Program Files\MinGHC-7.8.4\ghc-7.8.4\lib\include, but linking fails with
1>main.obj : error LNK2001: unresolved external symbol _HsEnd
1>main.obj : error LNK2001: unresolved external symbol _freegrep
1>main.obj : error LNK2001: unresolved external symbol _grep
1>main.obj : error LNK2001: unresolved external symbol _HsStart
1>C:\Code\Grep\dist\Win32\Release\Grep.exe : fatal error LNK1120: 4 unresolved externals
The exact same process works when I build with 32-bit, but not 64-bit. What could I be doing wrong? (I am building a 64-bit app when attempting to link the 64-bit library.)
Source files:
Grep.hs
{-# LANGUAGE ForeignFunctionInterface #-}
module Grep where
import Foreign
import Foreign.C.String
import Data.List (isInfixOf)
filterlines f = unlines . filter f . lines
grep :: CString -> CString -> IO CString
grep i s = do
ii <- peekCString i
ss <- peekCString s
newCString $ (filterlines (isInfixOf ii)) ss
freegrep :: CString -> IO ()
freegrep s = free s
foreign export ccall grep :: CString -> CString -> IO CString
foreign export ccall freegrep :: CString -> IO ()
StartEnd.c
#include <Rts.h>
void HsStart()
{
int argc = 1;
char* argv[] = {"ghcDll", NULL}; // argv must end with NULL
// Initialize Haskell runtime
char** args = argv;
hs_init(&argc, &args);
}
void HsEnd()
{
hs_exit();
}
main.cpp
#include <HsFFI.h>
#include <Grep_stub.h>
#include <iostream>
extern "C" {
void HsStart();
void HsEnd();
}
int main(int argc, char* argv[])
{
HsStart();
HsPtr str;
str = grep("test", "This is a test\nwith many lines\nand it failed\nand the test passed");
if (str)
{
std::cout << (char*) str;
freegrep(str);
}
HsEnd();
return 0;
}
Thanks to the comments, I added the actual error output to the post. This caused me to notice that Visual Studio's confusing configuration management interface had bit me once again. It was still trying to build the Win32 version even though my configuration setting said x64. Long story short, it's working!

C++ Program to connect with MySQL

I am new to C++ (although I have some experience with C) and MySQL and I am trying to make a program that reads a database from MySQL, I have been following this tutorial but I get an error when I try to 'build' the solution. (I am using Visual C++ 2008 just like they do in the tutorial.
Compiling...
test2.cpp
c:\users\rafael\documents\visual studio 2008\projects\test2\test2\test2.cpp(43) : warning C4244: 'initializing' : conversion from 'my_ulonglong' to 'unsigned int', possible loss of data
Compiling manifest to resources...
Microsoft (R) Windows (R) Resource Compiler Version 6.0.5724.0
Copyright (C) Microsoft Corporation. All rights reserved.
Linking...
test2.obj : error LNK2019: unresolved external symbol _mysql_close#4 referenced in function _main
test2.obj : error LNK2019: unresolved external symbol _mysql_fetch_row#4 referenced in function _main
test2.obj : error LNK2019: unresolved external symbol _mysql_num_rows#4 referenced in function _main
test2.obj : error LNK2019: unresolved external symbol _mysql_store_result#4 referenced in function _main
test2.obj : error LNK2019: unresolved external symbol _mysql_query#8 referenced in function _main
test2.obj : error LNK2019: unresolved external symbol _mysql_real_connect#32 referenced in function _main
test2.obj : error LNK2019: unresolved external symbol _mysql_init#4 referenced in function _main
C:\Users\*****\Documents\Visual Studio 2008\Projects\test2\Debug\test2.exe : fatal error LNK1120: 7 unresolved externals
I followed the tutorial and I cannot figure out what's going on, I guess it's something to do with the linkers, but I do not know what could I do.
This is the code I am using (source):
#include "stdafx.h"
#include "my_global.h" // Include this file first to avoid problems
#include "mysql.h" // MySQL Include File
#define SERVER "localhost"
#define USER "root"
#define PASSWORD "********"
#define DATABASE "test"
int main()
{
MYSQL *connect; // Create a pointer to the MySQL instance
connect=mysql_init(NULL); // Initialise the instance
/* This If is irrelevant and you don't need to show it. I kept it in for Fault Testing.*/
if(!connect) /* If instance didn't initialize say so and exit with fault.*/
{
fprintf(stderr,"MySQL Initialization Failed");
return 1;
}
/* Now we will actually connect to the specific database.*/
connect=mysql_real_connect(connect,SERVER,USER,PASSWORD,DATABASE,0,NULL,0);
/* Following if statements are unneeded too, but it's worth it to show on your
first app, so that if your database is empty or the query didn't return anything it
will at least let you know that the connection to the mysql server was established. */
if(connect){
printf("Connection Succeeded\n");
}
else{
printf("Connection Failed!\n");
}
MYSQL_RES *res_set; /* Create a pointer to recieve the return value.*/
MYSQL_ROW row; /* Assign variable for rows. */
mysql_query(connect,"SELECT * FROM TABLE");
/* Send a query to the database. */
unsigned int i = 0; /* Create a counter for the rows */
res_set = mysql_store_result(connect); /* Receive the result and store it in res_set */
unsigned int numrows = mysql_num_rows(res_set); /* Create the count to print all rows */
/* This while is to print all rows and not just the first row found, */
while ((row = mysql_fetch_row(res_set)) != NULL){
printf("%s\n",row[i] != NULL ?
row[i] : "NULL"); /* Print the row data */
}
mysql_close(connect); /* Close and shutdown */
return 0;
}
Yes, it totally is a linker problem: it is almost surely missing the mysql library. In the project settings you should add the name (and the path) of the .lib you intend to use.

Linker error when installing MessagePack implementation for C and C++

I'm following the instructions, which tell me to download msgpack 0.5.4 for C & C++.
On Windows, download source package from here and extract it. Open msgpack_vc8.vcproj or msgpack_vc2008 file and build it using batch build. It builds libraries in lib/ folder and header files in include/ folder.
You can build using command line as follows:
vcbuild msgpack_vc2008.vcproj
dir lib % DLL files are here
dir include % header files are here
vcbuild msgpack_vc2008.vcproj has been replaced by MSBuild msgpack_vc8.vcxproj. I used Visual studio 2012 to convert the project to have the correct .vcxproj for this. Batch build in Visual studio and running MSBuild gives the same result, so I will speak for both of them from this point on.
After the project is converted, I noticed the project was set to output to .lib, rather than .dll, so I altered that setting to match my needs. When compiling there was one small error:
...\microsoft visual studio 11.0\vc\include\stdint.h(8): error C2371: 'int8_t' : redefinition; different basic types
...msgpack-0.5.4\src\msgpack\sysdep.h(23) : see declaration of 'int8_t'
So I changed the line
typedef __int8 int8_t;
to
typedef signed __int8 int8_t;
which solves that minor issue. But then we arrive at where I'm at now. This linker error:
objectc.obj : error LNK2019: unresolved external symbol __imp__ntohl#4 referenced in function _msgpack_pack_array
unpack.obj : error LNK2001: unresolved external symbol __imp__ntohl#4
objectc.obj : error LNK2019: unresolved external symbol __imp__ntohs#4 referenced in function _msgpack_pack_array
unpack.obj : error LNK2001: unresolved external symbol __imp__ntohs#4
...\msgpack-0.5.4\Debug\MessagePack.dll : fatal error LNK1120: 2 unresolved externals
I've searched for parts of this error:
In sysdep.h:
#define _msgpack_be16(x) ntohs(x)
#define _msgpack_be32(x) ntohl(x)
In object.c:
case MSGPACK_OBJECT_ARRAY:
{
int ret = msgpack_pack_array(pk, d.via.array.size);
if(ret < 0) { return ret; }
msgpack_object* o = d.via.array.ptr;
msgpack_object* const oend = d.via.array.ptr + d.via.array.size;
for(; o != oend; ++o) {
ret = msgpack_pack_object(pk, *o);
if(ret < 0) { return ret; }
}
In unpack.c:
static inline int template_callback_array(unpack_user* u, unsigned int n, msgpack_object* o)
{
o->type = MSGPACK_OBJECT_ARRAY;
o->via.array.size = 0;
o->via.array.ptr = (msgpack_object*)msgpack_zone_malloc(u->z, n*sizeof(msgpack_object));
if(o->via.array.ptr == NULL) { return -1; }
return 0;
}
And that's about all I know. If there's another way of how to obtain the .dll, that would be helpful too. Thank you in advance. :)
You need to link the ws2_32.lib library since ntohl is a winsocket API function.
That should fix the problem!

C++ error C4430 int assumed

I'm a newbie in C++ and have just a small header file in C++ with a simple struct in it.
PGNFinder.h:
#ifndef PGNFINDER_H
#define PGNFINDER_H
struct Field
{
int Order;
string Name;
//more variables but doesn't matter for now
};
#endif
This gives the next errors:
error C2146: syntax error : missing ';' before identifier 'Name'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
when I change it to:
struct Field
{
int Order;
std::string Name;
};
It gives a error in the .exe file and the .obj file
error LNK1120: 1 unresolved externals (in the .exe file)
error LNK2019: unresolved external symbol "int __cdecl Convert::stringToInt(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?stringToInt#Convert##YAHV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z) referenced in function "private: void __thiscall CAN::calculateMessageLength(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?calculateMessageLength#CAN##AAEXV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z)
and when I add
#include <string>
and change back to
string Name;
It gives the same errors as in the beginning.
So why can't the header file recognize the int and string?
Thanks for the help :)
In order to use string as type of a variable, you need to
include the header in which it is declared (#include <string>)
use a full qualified type such as std::string or by means of the using directory using namespace std; Note, however, that using is not recommended in header files (see "using namespace" in c++ headers)
If you only try one of these, it won't work.
However, your second error message seems to point to a linker problem.
Since I tend to use the comment function too often.
Your problem is a missing include, and when you included string.h you still forgot the std-namespace of the "string class".
So either use a using namespace std (for beginners best practice, since most stuff will be most likely std stuff)
or declare your string as std::string within your struct.
changing it to std::string clearly fixes the compiler error.
Then you have a linker error which is not related to that line of code. You appear to have a 'Convert' class with a missing implementation of a 'stringToInt' function.