When I include:
extern "C" {
#include <libavcodec/avcodec.h>
}
I am getting the error:
undefined reference to QVideoSurfaceFormat::QVideoSurfaceFormat(QSize
const&, QVideoFrame::AVPixelFormat, QAbstractVideoBuffer::HandleType)
without the include - build success.
My guess that include brings some defines that breaks QVideoSurfaceFormat defenition.
Have someone faced with the similar issue?
#define __STDC_CONSTANT_MACROS // to fix #include <stdint.h> issue
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
}
After reading through stdint.h and related topic in the web, found solution, that works for me:
#define __STDC_CONSTANT_MACROS
Related
When I add winsock2 to my MinGW-w64 C/C++ project, it then gets make error:
undefined reference to `InitializeConditionVariable'.
NOTE: InitializeConditionVariable built and ran ok prior to adding Winsock.
main.c ...
#undef UNICODE
#define WIN32_LEAN_AND_MEAN
#include <winsock2.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include "infrastructure.h"
#include "common.h"
#include "bg.h"
#include "aox.h"
#include <windows.h>
#include <ws2tcpip.h>
#include <synchapi.h>
. . .
static void mutexInit()
{
#ifdef WINDOWS
// Initialize critical sections and condition variables
InitializeCriticalSection(&iqSamplesCriticalSection);
InitializeCriticalSection(&bgBufferCriticalSection);
InitializeConditionVariable(&newSamplesAvailable); <<<<<<<<<<<<<<<<<<< ERROR: undefined reference
#else
// Initialize mutexes
pthread_mutex_init(&iqSamplesCriticalSection, NULL);
pthread_mutex_init(&bgBufferCriticalSection, NULL);
pthread_cond_init(&newSamplesAvailable,NULL);
#endif
}
InitializeConditionVariable() has nothing to do with WinSock. This is strictly an issue with your own code.
InitializeConditionVariable() was introduced in Windows Vista. You are likely just linking to an out-dated kernel32.lib that doesn't expose newer Vista+ APIs. So, you can either:
update the Windows SDK for your compiler.
load the various ConditionVariable functions dynamically at runtime using GetProcAddress().
I am a beginner at c++ and I'm having this problem with nested include files. The code is too big to put here, but this is the part that I'm getting the error:
cvblob.h
#ifdef SWIG
%module cvblob
%{
#include "cvblob.h"
%}
#endif
#ifndef CVBLOB_H
#define CVBLOB_H
#include <iostream>
#include <map>
#include <list>
#include <vector>
#include <limits>
#include <opencv2/opencv.hpp>
#ifndef __CV_BEGIN__
#define __CV_BEGIN__ __BEGIN__
#endif
#ifndef __CV_END__
#define __CV_END__ __END__
#endif
#ifdef __cplusplus
extern "C" {
#endif
...
At line 4 in the above code (#iclude "cvblob.h"), the error happens:
[package_tracking/cvblob/cvblob.h:26]: (error) #include nested too
deeply
The guards are already used, but the error doesn't go away. Sorry that I am not able to put the entire code. If it is not possible to figure it out without the entire code, please answer these questions:
Should I put the guards (#ifndef CVBLOB_H) before the first line?
Is it necessary to put the guards in all the header files?
Thank you! I appreciate any suggestions.
ScriptInterface.h
extern "C"
{
#include "kel.h"
#include "process.h"
#if defined(SIMULATOR_COMPILE_FROM_SCRIPTINTERFACE) || defined(SIMULATOR_WIN)
#include "sigtypes.h"
#endif
}
In windows platform this is not giving any errors(below code)
xyz.cpp
#include "kel.h"
#include "process.h"
#include "sigtypes.h"
#include "ScriptInterface.h"
Whereas it is giving 'Symbol look up error' in Linux platform. Is there any different behavior of extern 'C' in Linux platform?
_Z16KEL_MEM_AllocateP19KEL_MEM_tPoolHandlej is very much a mangled name and it's almost certainly there because you're including kel.h outside of the extern "C" block.
Get rid of the first three includes in xyz.cpp and just use the ones you include from within ScriptInterface.h (which are marked as non-mangling).
I am trying to link to ffmpeg under windows, but have run into difficulties. Inclusion of ffmpeg headers causes hundreds of compilation errors which i can't easily fix.
1) timestamp.h uses snprintf instead of _snprintf. I have tried to add it as a macro, like this:
#ifdef Q_OS_WIN
#define snprintf _snprintf
#endif
#define __STDC_CONSTANT_MACROS
namespace ffmpeg {
extern "C" {
#include <libavutil/imgutils.h>
#include <libavutil/samplefmt.h>
#include <libavutil/timestamp.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
} }
but it didn't help. Why would the macro not propagate inside?
2) There again, PRId64 isn't defined. I have defined __STDC_CONSTANT_MACROS before inclusion of timestamp.h, but definition isn't retrieved from inttypes.h
In compiler output, it looks like:
ffmpeg\include\libavutil/timestamp.h(42) : error C3861: 'snprintf': identifier not found
ffmpeg\include\libavutil/timestamp.h(42) : error C2146: syntax error : missing ')' before
identifier 'PRId64'
You did include them into a extern "C" right?
extern "C" {
#include <libavutil/imgutils.h>
#include <libavcodec/avcodec.h>
#include <libswscale/swscale.h>
}
Is this a typo? You talk about "snprintf" ("n", not "m").
#define smprintf _snprintf
Even then, timestamp.h probably redifines it or includes something that does.
During linking code on ubuntu I get following error
undefined reference to 'std::__default_alloc_template<true, 0>::deallocate(void*, unsigned int)'
I tried several g++ compilers but nothing changes. The reason I found in previous answers is wrong configuration if includes. Here are includes in the code:
#pragma warning(disable:4786)
#include <stdio.h>
#include <map>
#include <string>
#include <vector>
#include <png.h>
#include <math.h>
#include <ft2build.h>
#include <gd.h>
#include FT_FREETYPE_H
using namespace std;
#ifndef WIN32
#define stricmp strcasecmp
#else
#include <io.h>
#include <fcntl.h>
#endif
Please help to fix those includes?
Your are probably compiling and linking with gcc instead of g++. For compilation, there's not much difference. GCC uses the file extension to guess the real language, but when linking, g++also pulls in the C++ Standard library, which is where allocators are usually defined.