JRTPLIB/header include problem - c++

I'm having some problems with JRTPLIB c++ win32 version, compiling in visual studio2010.(http://research.edm.uhasselt.be/~jori/page/index.php?n=CS.Jrtplib). I've emailed the author but have yet to received a reply. The problem I am experiencing is this:
error C1083: Cannot open include file: 'rtpconfig_unix.h': No such file or directory c:\users\johan-bar\desktop\developer tools\3rd party software\jrtplib-3.8.1\src\rtpconfig.h
The two .h files I have are these:
MAIN.h:
enter code here
#include <WinSock2.h>
#include <Windows.h>
#include <WindowsX.h>
#include <stdlib.h>
#include <string>
#include <Richedit.h>
#include "jrtlibtest.h"
#include "resource.h"
jrtlibtest.h:
#include "rtpsession.h"
So I reason that I need to #include windows.h in jrtlibtest.h for it to recognise WIN32 to be defined (so it does not include unix .h files) but that in turn gives me about 100 redifinition errors.
I am unsure how to solve this problem and I can't find any information on the library homepage itself or on the internet. Has anyone else encountered this problem?
Cheers

I have not seen JRTPLIB c++ lib, but based on information that you provided ('rtpconfig_unix.h'can not be opened), it seems that it is taking default file for unix port? Look for something like a config file in the JRTPLIB folder and run it (./config on cygwin or something). That should generate the windows config files that you would be able to #include in your code.
Good luck!!
EDIT:
The fact that you are getting the error:
error C1083: Cannot open include file: 'rtpconfig_unix.h':
means: in your rtpconfig.h, the WIN32 macro is not enabled:
#ifndef RTPCONFIG_H
#define RTPCONFIG_H
#if (defined(WIN32) || defined(_WIN32_WCE))
#include "rtpconfig_win.h"
#else
#include "rtpconfig_unix.h"
#endif // WIN32
//#define RTPDEBUG
#endif // RTPCONFIG_H
And thatÅ› why it says it cant open rtpconfig_unix.h file.
Did you try #defining win32 macro in rtpconfig.h directly? (or do it in your project settings).

Include ws2_32.lib in your project. Had the same problem.
(And remove if you already include it, wsock32.lib and winsock.h header file to avoid colissions)

What are the redefinition errors?
If they are from winsock, removing winsock2.h from your includes might help.

Related

Unable to use Precompiled headers in visual studio

I've seen several questions discussing this topic but none of their solutions seems to apply here. I have several libraries that I don't wont to be compiled every time I build the project so I've created "b5pch.h" and b5pch.cpp" files.
//b5pch.h
#pragma once
#include <iostream>
#include <memory>
#include <utility>
#include <algorithm>
#include <functional>
#include <sstream>
#include <string>
#include <vector>
#ifdef B5_PLATFORM_WINDOWS
#include <Windows.h>
#endif
//b5pch.cpp
#include "b5pch.h"
In properties I've set precompiled header for every cpp file to be Use(/Yu) like so:
And for b5pch.cpp it's set to Create(/Yc)
after that I've added #include "b5pch.h at the start of each cpp file(I only have two not including b5pch.cpp) but when I try to build the project I get two errors saying exactly the same thing
Error C1010 unexpected end of file while looking for precompiled header. Did you forget to add '#include "b5pch.h"' to your source?
Okay I've fixed the problem. when I was including b5pch.h in my cpp files I was doing it like this:
#include ../b5pch.h since they were in different directories.
When I moved pch files in same directory and I just wrote #include b5pch.h there were no more errors. I didn't wanted them to be in same folder so I've moved them back out but in Project Properties->Additional Include Directories I've added "src" so I could just use #include b5pch.h in my cpp files even tho they were not in the same folder.

Project "Additional include directory" being ignored

I'm including files from another project in the same solution - it's all worked fine in it's current configuration but I added a new method, and now it can't find any of the include files.
Here's the header file dems_gridmanagement.h:
#ifndef dems_gridmanager_h
#define dems_gridmanager_h 1
//## begin module%500EBD96007C.includes preserve=yes
#pragma once
#include <QObject>
#include <QTime>
#include <QString>
#include "common_StringUtility.h"
#include "common_SharedMemory.h"
#include "common_QtThread.h"
#include "common_QtThreadable.h"
#include "sma_Maps.h"
#include "dems_Types.h"
...
#include "MQTTs_UDP_Multicast.h"
...
And in the additional include directory:
.\GeneratedFiles;$(QTDIR)\include;.\GeneratedFiles\$(Configuration);$(QTDIR)\include\qtmain;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtSql;.\;..\Common;..\DemsCommon;..\Ethernet;..\SMA;..\ModbusTCPIP;..\MQTTs;%(AdditionalIncludeDirectories)
Crucially, it includes the "..\SMA", which should allow the "sma_Maps.h" to be found, but I'm getting:
Error 3 error C1083: Cannot open include file: 'sma_Maps.h': No such file or directory c:\users...\solution\projects\DemsGridManagement\dems_GridManager.h 33
I tried changing it to:
#include "../SMA/sma_Maps.h"
which get's rid of the error, but then introduces a new error:
Error 59 error C1083: Cannot open include file: 'MQTTs_UDP_Multicast.h': No such file or directory c:\users...\solution\projects\DemsGridManagement\dems_GridManager.h 39
And also a similar error for an include in a project file that is in a completely different project within the solution, and I haven't even opened or changed anything in.
For some reason, it's like the solution is just selectively ignoring the include directory information with some of the project files, but not others (QT includes work fine, so do the "common" project includes...
Does anyone have any ideas what could be causing this? It was all working fine yesterday!
Edit: Narrowed it down. I added a reference to GridManager from another project:
#include "../DemsGridManagement/dems_gridmanager.h"
If I remove this, there's no problems in the dems_gridmanager.h file. If it's here, the includes in gridManager go crazy and break.
When including with #include "filename" it always search the same directory as the current file. To get the files you have included in "additional include directories" you should include with #include <filename>

error must include nuiapi.h rather than including nuisensor.h directly

I am trying to build some code written in C++ for getting an image via Kinect and I get the following error:
You must include nuiapi.h rather than including nuisensor.h directly.
but I already included windows.h and NUIAPI.h... windows.h was included before nuiapi.h in the source file. Can anyone tell me what is wrong?
here is the code in my source file .cpp
#include <Windows.h>
#include "Kinect.h"
#include <NuiApi.h>
#include <NuiImageCamera.h>
#include <NuiSensor.h>
kinectcamera::~Kinectcamera()
{
SafeRelease<IMediaObject>(&pDMO);
SafeRelease<INuiAudioBeam>(&pAudio);

Boost::asio winsock and winsock 2 compatibility issue

My project uses windows.h in which winsock.h is used, and I need to include boost:assio which uses winsock2. So I get many errors that says Winsock.h already included.
I can define WIN32_LEAN_AND_MEAN. so that windows.h wouldn't use winsock. The problem is , that I need windows.h to use it, and I just need Asio for asynchronous timers. I don't need its winsock2.h . I tried searching how to disable its winsock2 use, and I found that I could do that by defining BOOST_ASIO_NO_WIN32_LEAN_AND_MEAN before including boost:asio, but I still get the same error.
#include <windows.h>
#define BOOST_ASIO_NO_WIN32_LEAN_AND_MEAN
#include <boost/asio.hpp>
Error
1>c:\program files\boost\boost_1_47\boost\asio\detail\socket_types.hpp(22): fatal error C1189: #error : WinSock.h has already been included
Try and change the order of includes. Start with boost/asio.hpp and put windows.h after it.
Usually the writers of any code library solve the compatibility issues but they can do it better if their code is the first to meet the compiler and preprocessor.
There's a similar issue with ACE, including ace/OS.h before anything else solves it.
As Danius (the OP) points out a compile with
#include <windows.h>
#include <boost/asio.hpp>
fails with this error:
1>c:\source\<SNIP>\boost\1.51.0\boost\asio\detail\socket_types.hpp(22): fatal error C1189: #error : WinSock.h has already been included
On the other hand
#include <boost/asio.hpp>
#include <windows.h>
Produces a bunch of noise and sets the windows version # incorrectly
1? Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately. For example:
1> - add -D_WIN32_WINNT=0x0501 to the compiler command line; or
1> - add _WIN32_WINNT=0x0501 to your project's Preprocessor Definitions.
1> Assuming _WIN32_WINNT=0x0501 (i.e. Windows XP target).
I couldn't find any way around this that didn't leave a bad taste, but this:
#ifdef _WIN32
# ifdef USE_ASIO
// Set the proper SDK version before including boost/Asio
# include <SDKDDKVer.h>
// Note boost/ASIO includes Windows.h.
# include <boost/asio.hpp>
# else // USE_ASIO
# include <Windows.h>
# endif // USE_ASIO
#else // _WIN32
# ifdef USE_ASIO
# include <boost/asio.hpp>
# endif // USE_ASIO
#endif //_WIN32
Does produce a clean compile.
<EDITORIAL> It shouldn't be that hard </EDITORIAL>
For me, switching the order of includes caused compile errors with another Microsoft include I was using - that was declaring things with "typedef interface".
Since my error was coming from socket_types.h, from these lines:
# if defined(_WINSOCKAPI_) && !defined(_WINSOCK2API_)
# error WinSock.h has already been included
# endif // defined(_WINSOCKAPI_) && !defined(_WINSOCK2API_)
I put an include of "winsock2.h" before the Windows.h, and then finally the boost/asio.hpp include, and things then compiled happily.
#ifdef BOOST_OS_WINDOWS
#define _WIN32_WINNT 0x0501
#if _WIN32_WINNT <= 0x0501
#define BOOST_ASIO_DISABLE_IOCP
#define BOOST_ASIO_ENABLE_CANCELIO
#endif
#endif
An other workarround I used is to concentrate all asio dependent
code in an XXX.hpp file and include it on the top of each windows implementing
XXX.cpp file where you use its objects.
this method place the include asio above any other include windows.h and work arround the problem.

How to check if MS compiler will compile my source code

Guys I was trying in VS to do something like:
#ifdef _MSC_VER
#include "stdafx.h"
#endif
but I'm getting an error telling me:
C1020: unexpected #endif
What is the correct way to do it?
Edit
/This is content of stdafx.h/
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#include "targetver.h"
//#include <stdio.h>
//#include <tchar.h>
#include <iostream>
using std::cout;
using std::cerr;
// TODO: reference additional headers your program requires here
You cannot put conditionals around stdafx.h because of the way MSVC precompiled headers work. It basically replaces everything once stdafx.h has been found (and usually requires #include "stdafx.h" to be the first line in the file) with the precompiled header contents, so it is as if you never wrote #if _MSC_VER and have an extra #endif.
Two solutions:
1) Do not use precompiled headers in your project. You can still use stdafx.h to include all the headers you require but compilation will be slow.
2) Put the conditional compile within the stdafx.h file.
(Taken from here)