Using vcpkg and compiling in Visual Studio 2015 - c++

I am trying to compile (by porting) some code in Windows 10 that was originally developed for Linux.
The code depends on 2 external libraries: cppkafka and librdkafka.
I saw that vcpkg is able to get the libraries, compile them, and then make them automatically available in Visual Studio 2015 (through the vcpkg integrate install command).
I see that the vcpkg compiles the dependencies for windows 64 (cppkafka and librdkafka) properly, as the .dll, .lib... are all made available on the install folder of vcpkg.
When I try compiling my code in Visual Studio 2015, I see errors concerning the dependencies headers, which for me is unexpected. If vcpkg compiled them, why Visual Studio doesn't? From the vcpkg documentation, I assume they use the same compiler. Next I show some example errors I am getting:
1>------ Build started: Project: AndreKafkaDriver, Configuration: Release x64 ------
1>C:\...\vcpkg\installed\x64-windows\include\librdkafka/rdkafka.h(64): error C2371: 'ssize_t': redefinition; different basic types
1> C:\Siemens\Automation\WinCC_OA\3.16\api\include\winnt\win32.h(47): note: see declaration of 'ssize_t'
1>c:\...\vcpkg\installed\x64-windows\include\cppkafka\header_list.h(265): warning C4267: 'argument': conversion from 'size_t' to 'ssize_t', possible loss of data
1>C:\...\vcpkg\installed\x64-windows\include\cppkafka/utils/buffered_producer.h(1035): error C2065: 'queue1': undeclared identifier
1>C:\...\vcpkg\installed\x64-windows\include\cppkafka/utils/buffered_producer.h(1035): error C2065: 'queue2': undeclared identifier
1>C:\...\vcpkg\installed\x64-windows\include\cppkafka/utils/buffered_producer.h(1035): error C2065: 'mutex': undeclared identifier
1>C:\...\vcpkg\installed\x64-windows\include\cppkafka/utils/buffered_producer.h(1035): error C2275: 'std::mutex': illegal use of this type as an expression
1>C:\...\vcpkg\installed\x64-windows\include\cppkafka/utils/buffered_producer.h(1035): note: see declaration of 'std::mutex'
1>C:\...\vcpkg\installed\x64-windows\include\cppkafka/utils/buffered_producer.h(1035): error C2182: 'swap_queues': illegal use of type 'void'
1>C:\...\vcpkg\installed\x64-windows\include\cppkafka/utils/buffered_producer.h(1035): error C2470: 'cppkafka::BufferedProducer<BufferType,Allocator>::swap_queues': looks like a function definition, but there is no parameter list; skipping apparent body
1>C:\...\vcpkg\installed\x64-windows\include\cppkafka/utils/buffered_producer.h(1035): error C2072: 'cppkafka::BufferedProducer<BufferType,Allocator>::swap_queues': initialization of a function
1>kafkaHWService.cxx(29): fatal error C1083: Cannot open include file: 'execinfo.h': No such file or directory
...
Thanks in advance,
Nerea

Related

Why is my code not compiling when including OpenCV in my Visual Studio Project?

There is too much code to post so I'll be short and sweet here.
I'm migrating a project to Visual Studio that I originally built in Eclipse on OSX, using the OpenCV Apple framework distribution (opencv delivered as a .framework).
I've created a visual studio project from the existing code but when I build it, I get a bunch of errors from one of the headers (opencv2/core/fast_math.hpp) that are included along the header chain of <opencv2/opencv.hpp>.
1>c:\users\blah\tools\lib\opencv\build\include\opencv2\core\fast_math.hpp(105):
error C2065: '__m128d': undeclared identifier
1>c:\users\blah\tools\lib\opencv\build\include\opencv2\core\fast_math.hpp(105):
error C2146: syntax error: missing ';' before identifier 't'
1>c:\users\blah\tools\lib\opencv\build\include\opencv2\core\fast_math.hpp(105):
error C2065: 't': undeclared identifier
1>c:\users\blah\tools\lib\opencv\build\include\opencv2\core\fast_math.hpp(105):
error C3861: '_mm_set_sd': identifier not found
1>c:\users\blah\tools\lib\opencv\build\include\opencv2\core\fast_math.hpp(106):
error C2065: 't': undeclared identifier
Nothing has really changed in my code, just that I'm now using Visual Studio 2017. I have added opencv\build\include to my include path. I see that this code is SIMD intrinsics, which I don't think should have any problem compiling.
Is there a step I'm missing here?
This looks to be something with how I set up the project. The SIMD intrinsics require extra headers. I didn't configure the project to use precompiled headers which also appears to explain why std::string was undefined too. The extra headers can be added in stdafx.h and it's presence resolves other missing components.

Libs ,DLLs and .h files

Im a C# guy thats why I'm lost here, this project claims to have compiled that library for Windows https://soildgeo.codeplex.com/releases/view/108738
the folder comes with Include,Lib64 and Bin64 folders. If I'm not mistaken, I only need to copy .lib files to the VC/lib folder and the folders in include to VC/include folder, so that I can start coding against these APIs, they appear in the #include<> intellisense but then they don't compile. my questions are, are my assumptions on this whole process is right ? if not what are the right steps ? and lastly, do I need to use the Dlls found in Bin64 folder at any point ?
Im using VS2013
Thanks in advance
Edit
1>------ Build started: Project: PhysBAMTest, Configuration: Debug x64 ------
1> main.cpp
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(163): error C2146: syntax error : missing ';' before identifier 'attribute'
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(163): error C2530: 'PhysBAM::LOG::anonymous-namespace'::cout' : references must be initialized
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(163): error C2065: 'unused' : undeclared identifier
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(163): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(163): error C2143: syntax error : missing ';' before '='
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(164): error C2146: syntax error : missing ';' before identifier '__attribute__'
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(164): error C2530: 'PhysBAM::LOG::anonymous-namespace'::cerr' : references must be initialized
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(164): error C2065: 'unused' : undeclared identifier
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(164): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(164): error C2374: 'PhysBAM::LOG::anonymous-namespace'::__attribute__' : redefinition; multiple initialization
1> C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(163) : see declaration of 'PhysBAM::LOG::anonymous-namespace'::attribute'
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(164): error C2143: syntax error : missing ';' before '='
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Edit
after adding the WIN32 macro based on an answer below , I got a linker error this time
Error 1 error LNK2019: unresolved external symbol "class std::basic_ostream > & __cdecl PhysBAM::LOG::cout_Helper(void)" (?cout_Helper#LOG#PhysBAM##YAAEAV?$basic_ostream#DU?$char_traits#D#std###std##XZ) referenced in function "void __cdecl PhysBAM::LOG::anonymous namespace'::dynamic initializer for 'cout''(void)" (??__Ecout#?A0x5bbeb782#LOG#PhysBAM##YAXXZ) C:\Users...\Documents\Visual Studio 2013\Projects\PhysBAMTest\PhysBAMTest\main.obj PhysBAMTest
All those attribute, unused, __attribute__ are what some call GNU-ishms, that is, features specific to the GCC compatible compilers (GCC itself, Clang, ICC and others). But MS VC does not aim for GCC compatibility, so they just don't work.
The people that did the port to Windows managed to remove these construct by using a few precompiler tricks, I think in the file Utilities/PHYSBAM_OVERRIDE.h. But for those to work you have to define the macro WIN32. Do that in the project "C/C++ Preprocessor Settings" page, not in the code, so it will be defined for all the source files at once.
Alternatively, and this IMO would be the correct solution, patch the sources, and replace every occurrence of #ifdef WIN32 or #if defined(WIN32) with #ifdef _WIN32. The macro _WIN32 is always predefined in Win32 and Win64, but the WIN32 is not.
Well, technically you'd have to differentiate each occurence if the issue is about being a Windows system or about being a MSVC compiler (there is a GCC compiler for Windows). And then use _WIN32 for the system dependencies and _MSC_VER for the compiler ones.
And then, if you feel like it, send a patch to the Codeplex project.
UPDATE
About the linker error, that should be easy to fix: just add the necessary "*.lib" file or files to the project. You can add them to the Linker Property Pageof the project.
Additionally what you did with .lib and .h, you need to keep .dll in either in, System32 dir, or in same dir where you have exe.
Answers to this question may help you understand better.

error C2065: 'errno' : undeclared identifier in <string> in Visual Studio 2012

I had a project running in Visual Studio 2010. Now I am using Visual Studio 2012.
Now I am getting below error while building the project.
I have looked into Google and SO as well. But no where I got any solution.
c:\program files\microsoft visual studio 11.0\vc\include\string(557): error C2065: 'errno' : undeclared identifier
2>c:\program files\microsoft visual studio 11.0\vc\include\string(557): error C2065: 'errno' : undeclared identifier
2>c:\program files\microsoft visual studio 11.0\vc\include\string(562): error C2065: 'errno' : undeclared identifier
2>c:\program files\microsoft visual studio 11.0\vc\include\string(574): error C2065: 'errno' : undeclared identifier
2>c:\program files\microsoft visual studio 11.0\vc\include\string(579): error C2065: 'errno' : undeclared identifier
I have tried with including stdlib.h into the sting header file but still I am getting this same error.
Any help appreciated.
There could be several possible reasons for this problem. The
first thing you should do is to create a one line source:
#include <string>
and nothing else, and try to compile it. If this doesn't
compile, there is a problem with your installation, and you
should reinstall it. Then, just to be sure, delete everything
in your source tree except the actual sources, project files and
solution, and rebuild. There may be some old files laying
around which are somehow causing the problem. I doubt it, but
this is something you should do anyway, any time you upgrade
a compiler, or even just install a patch. (If you've got
everything under source code control, which you should, the
simplest solution is just to delete everything, and do a new,
clean checkout.)
If these measures don't solve the problem (and somehow,
I suspect they won't), there's a problem in your code base
somewhere. errno is required to be a macro by the standard;
to get the error message you cite, the macro must be undefined.
<string> includes (indirectly) a file which defines it. Given
this, the only cause I can think of is that an earlier include
file has already included a file which defines errno, and then
#undefed it. To verify this, put your #include <string> as
the very first include of your source, and see if this solves
the problem. If it does, then you have to find the file which
does the #undef, and fix it.
I had the same issue. Strangely enough, the problem was not including "using namespace std;" under the header file includes. Apparently, program would recognize "string" unless I did this, even though "char", "float", etc were recognized.

Compiling and using NTL c++ library for Windows

I have compiled the NTL inifite precision integer arithmetic library for c++, using Microsoft Visual Studio 2008. I did as explained, on this site, using the Visual Studio interface, rather than from the command prompt. Actually I would rather do it from the command prompt, but I was not sure how to.
Anyhow, I got the library compiled, and I now want to compile a program using the library, from the command prompt. The program I am trying to compile, has been tested on a linux system, where I compile it with the following
c++ -I/appl/htopopt/Linux_x86_64/NTL-5.4.2/include mpqs.cpp main.cpp -o main -L/appl/htopopt/Linux_x86_64/NTL-5.4.2/lib -lntl -L/appl/htopopt/Linux_x86_64/gmp-4.2.1/lib -lgmp -lm
Nevermind the gmp stuff, I dont have that installed on Windows. It is purely an optional thing that will make the NTL run faster. Anyhow, this works fine on linux. Now on Windows I write the following
cl /EHsc /I D:\Downloads\WinNTL-5_5_2\include mpqs.cpp main.cpp /link /LIBPATH:"D:\Documents\Visual Studio 2008\Projects\ntl\Debug"
But this results in the following errors:
mpqs.cpp
mpqs.cpp(38) : error C2039: 'find_smooth_vals' : is not a member of 'QS'
d:\desktop\qs\mpqs.h(12) : see declaration of 'QS'
mpqs.cpp(41) : error C2065: 'M' : undeclared identifier
mpqs.cpp(41) : error C2065: 'n' : undeclared identifier
mpqs.cpp(42) : error C2065: 'sieve_table' : undeclared identifier
mpqs.cpp(42) : error C2228: left of '.size' must have class/struct/union
type is ''unknown-type''
mpqs.cpp(43) : error C2065: 'sieve_table' : undeclared identifier
mpqs.cpp(44) : error C2065: 'qx_table' : undeclared identifier
mpqs.cpp(44) : error C3861: 'test_smoothness': identifier not found
mpqs.cpp(45) : error C2065: 'smooth_indices' : undeclared identifier
mpqs.cpp(45) : error C2228: left of '.push_back' must have class/struct/union
type is ''unknown-type''
main.cpp
Generating Code...
It is as if, my mpqs.h file is not included into the compilation process? Also I dont understand why it complains about .push_back() for a vector type?
Help is much appreciated!
mpqs.h is definitely being included as the output asks you to refer to it.
Seeing as MPQS.h does not appear to be included in the NTL library ... did you write it? If so can you post the code up?
Also, shouldn't you included the library file somewhere on your build?
Edit: There is no function find_smooth_values so why should you expect MSVC to find it? I'm not sure why that compiles under GCC but its obviously missing. I'm guessing that the other errors are caused because of this one. The errors are telling you things. You should listen to them.
push_back is failing because it doesn't know what the type you are trying to push_back into is. This again is probably caused by the fact that find_smooth_values doesn't exist. Try adding the function prototype into the QS class. This may well fix all your problems.
As for the library it won't get to using the library until the compilation succeeds. So don't worry about that just now. Get in there and fix the errors that MSVC is reporting!

Building log4cxx on visual 2005

When I build the log4cxx on Visual 2005 according to instructions http://logging.apache.org/log4cxx/building/vstudio.html, I am getting error below;
1>------ Build started: Project: apr, Configuration: Debug Win32 ------
1>Compiling...
1>userinfo.c
1>c:\program files\microsoft visual studio 8\vc\platformsdk\include\rpcndr.h(145) : error C2059: syntax error : ':'
1>c:\program files\microsoft visual studio 8\vc\platformsdk\include\rpcndr.h(898) : error C2059: syntax error : ','
.
.
.
1>c:\program files\microsoft visual studio 8\vc\platformsdk\include\rpcndr.h(3119) : fatal error C1003: error count exceeds 100; stopping compilation
When clicking the first error moves to code below
/****************************************************************************
* Other MIDL base types / predefined types:
****************************************************************************/
typedef unsigned char byte;
typedef ::byte cs_byte; // error indicates here
Is there any comment??
Thanks
I remember having a problem building log4cxx.0.10.0 in windows (I don't remember if it was the exactly the same one you have) and I followed this steps.
I hope that helps.
The error looks very much like there is a #define or two missing. Did you successfully open and convert the project files as described in the build instructions?