‘memcpy’ was not declared in this scope when using gcc compiler - c++

Actually I'm trying to compile a c/c++ project with mingw. The same project is actually compiled with visual studio compiler. For this purpose, I have written a makefile and everything works so far.
During compiling I get error regarding functions which are declared withing string.h and stdio.h like memcpy() , printf()..., with following error:
error: 'memcpy' was not declared in this scope
That's because the compiler didn't find the functions. When compiling within visual studio, this error didn't appear, logically, because of compiler include paths like:
c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\
My question now is:
What should I do in my makefile to tell the compiler to use the "string.h" and "stdio.h" functions from the mingw. I tried to put the include path in the makefile, like:
INCLUDE_DIRS =\
C:\MinGW\include
but it has no effect.
And also, there is a difference between the string.h and stdio.h from visual studio and string.h and stdio.h used by gcc. Can this be a problem?

The correct way would be to add these includes to the source files where you use methods which are defined in them.
But if you insist to include it through the makefile, you can use force include.
Visual studio link.
To set this compiler option in the Visual Studio development
environment Open the project's Property Pages dialog box.
Open Project Property Pages.
Click the C/C++ folder.
Click the Advanced property page.
Modify the Force Includes property.
or use -include path_to_the_header for gcc
Just add this option to the compilation command line. Good luck.

Related

Visual studio include visibility

I got issue with includes in visual studio. I want to compile the project both for windows and linux.
In visual studio, I got a tiny class in .hpp file, which uses std::exception and std::is_pod<T> but I did not include type_traits nor stdexcept!! And the file compiles just fine with Visual Studio! Why?
Doing so on linux gives me error
In file included from Packet.hpp:3:0,
from AbstractPacketFactory.hpp:2,
from AuthenticationPacketFactory.hpp:2,
from AuthenticationPacketFactory.cpp:1:
ByteSerializer.hpp: In member function ‘byte_serializer& byte_serializer::operator>>(T&)’:
linux g++ is correct - why does visual studio not warn me? Is there something I can do about it? I am using VS as my primary IDE and I would like to avoid such surprise in future (currently there are 50 errors like that...)
I got a function where i made a mistake:
static_assert(std::is_pod<T>, "T must be a POD");
You have to use it with ::value or () - yet visual studio compiles std::is_pod<T> it without any warning. And that was the reason of error avalanche...
Your Visual Studio Projects might be configured to use Precompiled Headers to use. stdafx.h is there when you use Precompiled Header.
Just remove stdafx.h from Precompiled Headers and see if Compilation succeeds on windows.
You can find Precompiled Headers in Project Properties > C++ > Precompiled Header.
If you want to make cross platform projects you should remove that Precompiled setting.

fatal error: sal.h: No such file or directory

I know that there are other errors for certain header files with the same message of "No such file or directory", but my circumstances are a bit different as I will explain now.
I use the Code Blocks IDE and wanted to start using the UI Automation library. When I tried to include the header
#include UIAutomation.h
Code Blocks could not find the header. From there I looked around my computer and saw that the UIAutomation.h, UIAutomationCore.h... and the other UIAutomation headers were in an "Include" file in the "Microsoft SDKs" folder.... So I went to (Settings -> Compiler -> Search directories) and in there I added a new directory to the include folder where the UI Automation headers were:
C:\Program Files\Microsoft SDKs\Windows\v7.0A\Include;
and Code Blocks found the headers. However... another error appeared:
fatal error: sal.h: No such file or directory
and I searched for the sal.h in the "\Include" folder I had just written code for and there was no sal.h file. I understood everything up until here... I had to check if I had a sal.h folder somewhere else on my computer and I did, in a file somewhere in my Visual Studio 10 IDE folders (just to let u guys know, I use code blocks cause I have been using it for a long time, and only downloaded VS10 recently to use spy++). So then I thought ok... I'll do the same thing I did before again so that I can include those files too, so I go back into the Search directories section and add the directory:
C:\Program Files\Microsoft Visual Studio 10.0\VC\include
but from there a million different errors appeared, all refereeing to different issues. Can anyone tell me what I did wrong? All I wanted to do was use the UI Automation headers so that I can start coding with the library, but that is proving to be a bit difficult...
From what one can get from this related Q&A: 'How do I get sal.h' it's not possible to use this stuff with a different toolchain than MSVC (Visual Studio).
You may consider to configure MSVC as toolchain for this codeblocks project.

C++ Including Visual Studio header files in Qt project. <xstring> include error

I have found a library to generate barcodes (libbarpp). I would like to use this library in my Qt project.
Doing a svn checkout of the source: http://libbarpp.googlecode.com/svn/trunk/ reveals a nice VS example in the src folder. I opened the project in VS and found the included header files. I have included these header files in my Qt project, however i encountered a problem when several of the files required a system header file
#include <xstring>
In VS i can see the this file is located in (on my system):
c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xstring
However the files does not have any extension and i don't really know what to do with it.
Do i need to include something in my Qt project file in order to use this VS file?
I tried including
CONFIG += stl
to my Qt project file, but with no luck.
Any help or comments is greatly appreciated.
EDIT: I'm using Qt 5.2.1 with MinGW compiler
xstring is a Microsoft specific header that contains implementation of std::basic_string and some related specializations.
It shouldn't be included directly in the first place and unless the code you are talking about is using something implementation specific from that file you should be fine replacing it with just:
#include <string>

DLL include unordered_map is not compiling with visual studio compiler

I am trying to compile a DLL with MinGW and use it from an executable compiled with visual studio compiler.
One of source files from DLL is using hash_map<> and it can be compile with MinGW successfully.
When I change hash_map<> to std::tr1::unordered_map<> and add #include <tr1/unordered_map> to my code it's compiling successfully for visual studio compiler.(How can I force MinGW to use tr1 namespace?)
But When I am trying to compile the code with MinGW as a DLL and use it from an executable compiled with visual studio compiler it's giving error: cannot open include file 'tr/unordered_map'
must My DLL be compatible with cl and MinGW same time?
EDIT:
my commands for compiling are below:
g++ -shared -o stemming.dll stemming.cpp alphabet.cpp basic.cpp determinise.cpp fst.cpp hopcroft.cpp operators.cpp utf8.cpp -Wl,--output-def,stemming.def,--out-implib,libstemming.a
lib /machine:i386 /def:stemming.def
cl sfstMinGW.cpp SFST/stemming.lib
VC++ is trying to open a header file and can't find it in the include path. VC uses the INCLUDE environment variable to determine the paths to use when searching for header files. Since VC does not use the tr/ directory it's not going to find it. You need provide include statements for both VC and g++ and choose which one to use like below.
#if defined(_MSC_VER)
# include <unordered_map>
#else
# include <tr/unordered_map>
#endif
You need to make sure that you compile the application using the same implementation of unordered_map used by the DLL. This means you will need to update the include paths to use GCC's version of TR1 instead of MS's implementation of the standard headers.

Visual Studio 2010 compiling .cpp files as .c files

I'm working one a Visual Studio solution which was generated using CMake (not sure if this is relevant).
In this solution there a c file, I wanted to change it into a cpp file, so I renamed it and changed the extension.
However, Visual Studio still treats it like a c file and gives compiler errors whenever I add any c++ style code.
I'm stuck, any advice would be much appreciated.
Project Properties, Configuration, C/C++, Advanced, change "Compile As".