I'm trying to write and compile some C code which I would use frm MATLAB with VS 2012
Here is my header file:
#ifndef _DLLTEST_H_
#define _DLLTEST_H_
#include <iostream>
#include <stdio.h>
#include <windows.h>
extern "C" __declspec(dllexport) int Add(int a, int b);
#endif
And here is implementation:
#include "stdafx.h"
#include "nureader.h"
extern "C" __declspec(dllexport) int Add(int a, int b)
{
return (a + b);
}
Compilation goes fine, but when I try to load DLL to MATLAB, I getting a strange error:
>> [a,b] = loadlibrary('nureader.dll', 'nureader.h')
Error using loadlibrary (line 419)
Failed to preprocess the input file.
Output from preprocessor is:nureader.h
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\eh.h(27) : fatal error C1189: #error : "eh.h
is only for C++!"
Take a look at VS output
fatal error C1189: #error : "eh.h is only for C++!"
You want to write a C library, right? so don't include C++ in it. or compile with G++ but since you're using windows I don't think you have that option...
In any case, track down what includes "eh.h" and try without it. If it builds without it - great, if not - you will need to only isolate the C portion of your program. By looking at the code, you don't seem to need anything more than
#include <stdio.h>
#include <windows.h>
So try that.
Related
I am trying to use FFmpeg in VC++ 2010 so that i can use ffmpeg in to my VC++ Code , i first Install the FFmpeg in to machine by Help provided by youtube video "FFMPEG build for windows"
while building the sample code provided by ffmpeg (muxing.c) i got following error's
error C1189: #error : missing-D__STDC_FORMAT_MACROS /#define _STDC_FORMAT_MACROS
2 IntelliSense: #error directive: missing -D__STDC_FORMAT_MACROS / #define __STDC_FORMAT_MACROS
c:\users----\ffmpeg\ffmpeg\include\libavutil\timestamp.h
how to resolve this error
i have already done following
1.Project-->properties-->Configuration Properties--> VC++ Directories --> include dir {add all the header files from ffmpeg folder here}
in Configuration Properties--> C/C++-->Command Line-->Additional Options --> add {-D__STDC_CONSTANT_MACROS }
any help would be highly appreciate
Thanks
regards
Hello Thanx for your time.
Problem is sorted out by putting header files extern to main() body .
1. #define __STDC_CONSTANT_MACROS
2. extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
}
int main( int argc, char* argv[] ) {
av_register_all();
return 0;
}
Regards
kaushal
I wrote a simple code in Atmel Studio 6.1 to blink a LED.
#include <avr/io.h>
#include <delay.h>
int main(void)
{
...
return (0);
}
The problem is when I compile the code I get the following error:
delay.h: No such file or directory
I don't think delay.h is not available because it is in this folder:
C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native \3.4.2.1002
\avr8-gnu-toolchain\avr\include\avr\delay.h
What's actually going on?
You can use this to solve your problem.
#include <util/delay.h>
I am pretty new user of Eigen and have run into a weird problem. I am adding to a C++ project that uses OpenMP (Visual Studio 2012 compiler, /openmp set). I get a compilation error:
include\eigen\src/Core/products/Parallelizer.h(34): error C3861:
'omp_get_max_threads': identifier not found
I have tried to google around for an answer, but have failed to find a solution. We have another project, not using openmp, where Eigen has been used successfully for a while. Adding /openmp to that project did not trigger the problem. I also tried to disable openmp in Eigen, using the EIGEN_DONT_PARALLELIZE preprocessor directive. The problem persists. All suggestions to solve the problem are more than welcome.
Long comment, not really an answer: Something appears to be broken in your project. I'm using Eigen 3.2.9 as a reference, as you haven't specified which version you're using. In Eigen/Core (133) we have
#if (defined _OPENMP) && (!defined EIGEN_DONT_PARALLELIZE)
#define EIGEN_HAS_OPENMP
#endif
#ifdef EIGEN_HAS_OPENMP
#include <omp.h>
#endif
So, if you properly defined EIGEN_DONT_PARALLELIZE in your project, EIGEN_HAS_OPENMP shouldn't be defined and omp.h shouldn't be included. Additionally, in Parallelizer.h(30):
#ifdef EIGEN_HAS_OPENMP
if(m_maxThreads>0)
*v = m_maxThreads;
else
*v = omp_get_max_threads();
#else
*v = 1;
#endif
So if you had properly defined EIGEN_DONT_PARALLELIZE, you would not be getting the error you are getting.
Regarding the C3861 error, it means that the compiler is not able to find a declaration for omp_get_max_threads (called in Parallelizer.h). As that code is called within a #ifdef EIGEN_HAS_OPENMP as is the line #include <omp.h> in Core, and omp_get_num_threads is only wrapped in an #if defined( __cplusplus) you could add a check in Core or omp.h to make sure that the code is active
// This is in Eigen/Core
#ifdef EIGEN_HAS_OPENMP
static_assert(0, "OMP FILE IS INCLUDED IN CORE...");
#include <omp.h>
#endif
and
// This is in omp.h
static_assert(0, "OMP FILE IS PROPERLY INCLUDED...");
_OMPIMP int _OMPAPI
omp_get_num_threads(
void
);
You should get both as errors if omp is loaded correctly.
I'm experiencing some sort of issue trying to compile a perfectly (windows+linux tested) mpi+openmp software I wrote my own.
I've managed to install and set to work the omp-adapted version of clang, and it works flawlessly in a simple omp "hello world" I've prepared.
As well I've installed open-mpi via homebrew, and the mpi "hello world" is working as well.
Now there come the issue.
Firstly, not so much confident in clang and openmp working together, I've created a version of my software without openmp calls. This version (MPI-only) of the code has been compiled with no issue.
Now comes my real dilemma.
I've reverted back the omp sections of my code, and tried to compile it with both MPI and openMP flags (mpic++ wrapper with ompclang forced in and -fopenmp flag added). The output of the compiler verbose mode is here below.
[...]
/usr/local/Cellar/open-mpi/1.8.4/include/openmpi/ompi/mpi/cxx/mpicxx.h:39:10:
fatal error: 'utility' file not found
#include <utility>
^
[...]
/usr/local/Cellar/open-mpi/1.8.4/include/openmpi/ompi/mpi/cxx/mpicxx.h:39:10:
fatal error: 'utility' file not found
#include <map>
^
[...]
After this output I tried to compile something like this:
#include <iostream>
#include <map>
#include <utility>
int main(int argc,char* argv[]){
std::cout<<"Hello World!!!!"<<std::endl;
return 0;
}
And the output keeps me saying the compiler can't find map, utility AND iostream as well.
It appears to me the problem is the compiler doesn't know where to find the standard c++ libraries.
Can anyone of you tell me how to solve this? Thanks in advance
Have fun,
gf
EDIT:
I've found a good suggestion from this site:
http://lists.cs.uiuc.edu/pipermail/cfe-users/2013-November/000293.html
That helped me to solve the issue.
I post the OMP+MPI hello world if anyone ever needs to test them together.
#include <mpi.h>
#include "omp.h"
int main(int argc, char** argv) {
// Initialize the MPI environment
MPI_Init(NULL, NULL);
// Get the number of processes
int world_size;
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
// Get the rank of the process
int world_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
// Get the name of the processor
char processor_name[MPI_MAX_PROCESSOR_NAME];
int name_len;
MPI_Get_processor_name(processor_name, &name_len);
// Print off a hello world message
#pragma omp parallel
printf("Hello from thread %d, nthreads %d,from processor %s, rank %d out of %d processors\n", omp_get_thread_num(), omp_get_num_threads(),processor_name, world_rank, world_size);
// Finalize the MPI environment.
MPI_Finalize();
}
Have fun
gf
I'm usual to build with consider warning as error. I'm using Boost C++ 1.54.0 with MinGW 4.8.1, in particular I'm using ptree.
#include <iostream>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
This simple program cause the following errors:
typedef 'cons_element' locally defined but not used [-Wunused-local-typedefs] line 228, external location: \boost\tuple\detail\tuple_basic.hpp
typedef 'Str' locally defined but not used [-Wunused-local-typedefs] line 38, external location: \boost\property_tree\detail\xml_parser_write.hpp
typedef 'Str' locally defined but not used [-Wunused-local-typedefs] line 72, external location: \boost\property_tree\detail\xml_parser_write.hpp
typedef 'T_must_be_placeholder' locally defined but not used [-Wunused-local-typedefs] line 37, external location: \boost\bind\arg.hpp
Is a way to ignore this warnings?
gcc allows ignoring specific warnings since 4.6
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
...
...
#pragma GCC diagnostic pop
there are still some warnings that cannot be turend off this way, but it works for most
or do it like the other mentioned and add -Wno-unused-local-typedefs to the commandline