Including boost::nowide either as standalone version or part of Boost fails

Hello.

I'm trying to use boost::nowide and I'm struggling to make it all work.
First I tried with standalone version of nowide that does not require any pre-compilation and consists of just headers, which is very convenient because I've never precompiled any 3rd party library.

I added the root folder of nowide to my project in Visual Studio in project properties > C++ > General > Additional include directories, which is ...\nowide-standalone

This however resulted in linker errors that complained about unresolved externals for nowide::cin and nowide::cout.

I resorted to using the "master" version of nowide that has other boost libraries, thinking that if I used the more "complete" version I'd get rid of the linker errors (I'm not entirely sure what is the difference between this version and downloading the whole boost project though). I included it in the properties and added it as a directory for the Linker too.

I correctly included the needed header in my code as:
#include <include/boost/nowide/iostream.hpp
By the way - this is their folder structure.

However, all includes inside boost have wrong directories written in the code, so I would have to manually change all directories to /include/boost/... instead of their /boost/...

I haven't meddled with the structure of boost's folders at all - I downloaded it, correctly included the root dir and included it in my code.

EDIT---------------------------------------------------------

I investigated the issue. Using nowide\fstream works no problem, which I think is due to the fact that it's just a header without any .cpp file connected to it that requires precompilation.

But I looked around in the nowide root folder and found a .cpp file iostream.cpp in nowide_standalone (root)\src\. This file is still INSIDE the root, but in a different folder where iostream.hpp resides (namely nowide_standalone (root)\nowide\). Do I need to precompile this .cpp file? I looked in it too and it defined nowide::cout and nowide::cin


EDIT---------------------------------------------------------

What seems to do the trick (although it doesn't look as PRO as I'd like it to be) is adding iostream.cpp as source file to Visual Studio project, which makes it visible for the header and connects those two. With this I was able to run the program.

Do you have any suggestions as to how to avoid adding the nowide's .cpp file in all my future projects?
Last edited on
Do you have any suggestions as to how to avoid adding the nowide's .cpp file in all my future projects?

Avoid using nowide based console input and output.

If you want to use the nowide library under Windows and you require nowide support for console input and output you will need to add either the .cpp file to your project or add a library that contains the iostream.cpp object code to your project in the form of a library.


Last edited on
add either the .cpp file to your project


I did as you said (added nowide\...\iostream.cpp to my project) but every character displayed when running the program is either a square or a cross.

1. Trying different codepages doesn't do anything (65001 with/without BOM, 1252 etc).
2. Haven't used _setmode(_fileno(FILE), _O_U8TEXT); in my project
3. I keep everything narrow, by that I mean using std::string and char instead of their wider counterparts. Strings can handle UTF as they store bits and are encoding agnostic, to the best of my knowledge.
4. I save my source files as UTF-8 without BOM 65001
5. I use nowide\iostream and nowide\fstream
6. I use Lucida Console that supports Unicode


Avoid using nowide based console input and output


Why? I thought this was meant to make Unicode-programming easier on Windows, isn't that right? I even read on their boost page that this is kind of an ICU-backend, some sort of more user-friendly wrapper around ICU. Is that incorrect?
Last edited on
Why? I thought this was meant to make Unicode-programming easier on Windows, isn't that right?

You were asking about how to avoid adding something to all of your future projects. If you stay away from console input and output all you need are the #include files. The .cpp file is only required for console input and output. But no matter what you need to make sure you're using the boost/nowide class instead of the standard input and output functions.

I did as you said (added nowide\...\iostream.cpp to my project) but every character displayed when running the program is either a square or a cross.

Without seeing your code there is no way I can answer this question.

I even read on their boost page that this is kind of an ICU-backend, some sort of more user-friendly wrapper around ICU. Is that incorrect?

No, that is correct. Did you read the documentation for the boost::nowide class? Which version of the class are you trying to use, the standalone or full? I recommend you use the standalone version if possible. Did you try the sample programs in the documentation?

http://cppcms.com/files/nowide/html/

The project is too big to show in full, but what I tried to do to narrow my search for problematic places is to display a test string at the beginning of my main() function. This way I can ensure that nothing that happens further down has any influence over nowide::cin and nowide::cout.

Pasting this code at the very beginning of my main() function:
1
2
3
4
5
6
7
int main() {
	std::string s;
	nowide::cout << s;
	std::string cs;
	nowide::cin >> cs; nowide::cout << cs;
	// ...
}

gives the same "squares & crosses" results - no matter whether English or Polish.

|The most interesting thing about the issue is that I had a working test project where, before changing my "real" project, I was checking if everything works fine. Nowide on the test project worked fine before implementing nowide to the "real" project, however once the "real" project started to output garbage, so did the test project after I returned to it (sic!).

The test project main() code (nowide\iostream.cpp besides that):
1
2
3
4
5
6
7
8
9
10
11
12
#include "nowide\iostream.hpp"
#include "nowide\fstream.hpp"

int main() {
	nowide::cout << "zażółć gęślą jaźń" << std::endl;
	nowide::cout << "something different żżżż" << std::endl;
	std::string str;
	std::getline(nowide::cin, str);
	nowide::cout << str;
	nowide::cin.get();
	return 0;
}


I anticipate questions about the code:
1. Source file is 65001 encoded with the use of Advanced Save Options.
2. Project options are set to Unicode to avoid data loss.
3. nowide::iostream.cpp is included in the project.
4. The code, as I said, worked ok before I implemented nowide to my "real" project which is suuuuper bizzare.
4,5 Both projects have different solutions on Visual Studio 2017, if there ever was a suspiction that they may share some wrong settings.
5. I do use the standalone version of nowide.
Last edited on
Topic archived. No new replies allowed.