LIBTIFF not able to work with C++ project - c++

Libtiff is a C library, but I want to use it with a C++ project in Qt Creator. Does anyone know how to do this? I get compile time errors when I try to use the C library, so I'm not sure what to do.
The compile time error I get is:
c:\libtiff\libtiff\tiff.h:69: error: C4430: missing type specifier - int assumed. Note: C++ does not support default-int
for the line:
typedef TIFF_INT8_T int8;
plus a bunch of more similar errors. Someone please help.

You need to wrap the include statements on an extern C block --
extern "C"{
#include "tiff.h"
}
This tells the compiler to view those files as C, not C++, so you should not get strict C++ errors.

Related

MFC - D3DCOLORVALUE undefined in base MFC application

I'm using Visual Studio 2013 to create a new MFC Application.
I created the application using the setup wizard, left it on all the default values.
When testing if it even runs before adding anything it gave the compile error:
IntelliSense: identifier "D3DCOLORVALUE" is undefined
followed by a lot of:
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Why would this be happening in a stock standard application straight out of the wizard? And how would I get this working?
d2dbasetypes.h was giving the error when trying to define D2D_COLOR_F.
I googled the base type (D3DCOLORVALUE) and found that it's supposed to be in "D3D9Types.h"
I added #include "D3D9Types.h" to the top of the d2dbasetypes header file and it seems to have fixed the problem.
I don't know why this isn't included in the generated code by default...

Include Order and Hidden Dependencies

While looking for best pratices regarding include order, I was stumbling over this thread:
C/C++ include file order/best practices [closed]
#squelart was stating, that it is better pratice to include from local to global, as this reduces the chance of hidden dependencies. I just tested this in a VS2015 project with the following code:
StrTest.h
#pragma once
class CStrTest
{
public:
CStrTest();
~CStrTest();
std::string test;
};
StrTest.cpp
#include <string>
#include "StrTest.h"
CStrTest::CStrTest()
{
}
CStrTest::~CStrTest()
{
}
I couldn't reproduce the stated behaviour (hidden dependencie duo including string first in StrTest.cpp). The compiler gives me mulitple errors. So is this something out of the past or did I overlook something?
EDIT: VS2015 Compiler errors:
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int
Error C2039 'string': is not a member of 'std'
Error C3646 'test': unknown override specifier
So is this something out of the past
No, the hidden dependencies are the standard behaviour and do happen in modern compilers. I don't know of VS, but GCC and Clang do compile your shown program without any errors. Demo: https://wandbox.org/permlink/ATJndwrOwirpDgDd
The compiler gives me mulitple errors.
Although an "implicit" include is poor style, it is still technically well formed as far as the standard is concerned as long as the implicitly included file is guaranteed to be included by you or whoever wrote the header that includes it - standard headers have no such guarantees.
Therefore I would be against such compiler feature that considers implicit includes as errors. An explicitly enable-able warning would be much more suitable.
I think the point of hidden dependence problem discussed there is that typically each file includes several other files and if header is not self-contained then including it may work in cases when it's implicit dependences are included by some other header and break everything when those other headers change and / or get moved / removed. In short: use of headers with hidden dependencies lead to extremely fragile code.
// foo.hpp
#pragma once
#include <string> // if we remove this unrelated `StrTest.h` header will be broken
...
.
// main.cpp
#include "foo.hpp" // if we move this one line lower `StrTest.h` header will be broken
#include "StrTest.h" // accidentally works fine
...

error C2146 trying to compile a basic HLSL shader in C++

i've just started to learn the basics of HLSL using C++, im following the tutorials on a book, the first basic shader is:
float4 VS_Main( float4 pos:POSITION):SV_POSITION
{
return pos;
}
but i get a lot of errors at compile time:
error C2146: syntax error: ';' missing before the identifier 'VS_Main'
error C4430: missing type specifier, int assumed. Note: default-int is no longer supported
error C2146: syntax error : ')' missing before the identifier 'pos'
error C2059: syntax errorlooks like a function definition, but there is no formal parameter list.
error C2059: syntax error: '{'
it really looks like the compiler cant handle HLSL at all...maybe VS2012 express doesnt support HLSL?
thanks in advance
HLSL is not C++. You should compile shaders with shader compiler, and C++ with C++ compiler — do not mix. There are two options for compiling HLSL.
Use command-line utility fxc.exe that is included in DirectX SDK (docs and usage here at MSDN). It generates a file that you should load in runtime by some of the ways described here.
Compile your shader at runtime by using D3DCompileFromFile function.
There are pros and cons about each of the variants. In short, pre-compiling at build time gives you some time gain at runtime, while compiling at runtime is more flexible and comfortable at development stage (no need to remember to recompile it or to use post-build scripts) but is more error-prone. Choose by yourself.
The code looks fine for HLSL. If you want to compile it from within VS2012 set the ".fx" file to build using the HLSL shader compiler. Right click the file select properties. Then select General and Item Type should be set to HLSL compiler.
If you really want to make shaders using C++ you could look into C++AMP to see if it may suit your needs.
it really looks like the compiler cant handle HLSL at all...maybe VS2012 express doesnt support HLSL?
No C++ compiler does. It is not supposed to be handled by the compiler.
You need to turn it into a resource and copy it into the bin directory using post-build scripts, and load the HLSL at runtime.
See also: http://www.directxtutorial.com/Lesson.aspx?lessonid=11-4-5

Unable to compile CUDA C sources. Simple version is provided

Here is the problem...
For school project I need to write parallel application using CUDA C. Even the most simple example will not compile. I'm using Windows7 and MS visual studio. The code is taken from the book: CUDA by example. An introduction to general purpose GPU computing.
#include<iostream>
#include<cuda.h>
using namespace std;
__global__ void kernel(void){
}
int main(){
kernel<<<1, 1>>>();
cout << "Hello world" << endl;
return 0;
}
Here are the errors:
1>c:\users\administrator\documents\visualstudio2010\projects\test\test\test.cpp(6): error C2144: syntax error : 'void' should be preceded by ';'
1>c:\users\administrator\documents\visualstudio2010\projects\test\test\test.cpp(6): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\administrator\documents\visualstudio2010\projects\test\test\test.cpp(10): error C2059: syntax error : '<'
Do I need to set nvcc.exe as default compiler instead of cl.exe? If that is the case, how to do it?
Any help is much appreciated!
CUDA code needs to be written in a .cu file and compiled with the NVCC compiler. You are seeing the above errors because you have written your code in a .c or .cpp file and are trying to compile it with a C++ compiler (the Visual C++ compiler).
You have chosen the right book to learn CUDA from. However, you are not following all the steps given in the book. Please have a look at the details of compilation in the book :-)

include or project setting in msvc for uint8_t and similar types?

When I create a new msvc project and try using the type uint8_t I get the following compile error:
error C2065: 'uint8_t' : undeclared identifier
Is there a project setting or predefined include that I can use? I'd prefer not to typedef values explicitly.
You need to include <stdint.h> (or <cstdint>), which is not available prior to VS2k10 as far as I can tell.
If you're using an older version of cl you can search for an open source implementation that meets your licensing requirements, or if none exist you'll have to supply the typedefs yourself.
Boost library have some definitions for this. But it's only for C++.