I am trying to use ffmpeg library on windows in C++/Qt. This is my main function:
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
#define INT64_C(val) val##LL
#define UINT64_C(val) val##ULL
#include <QtCore>
#include <SDL/SDL.h>
#ifdef __MINGW32__
#undef main
#endif
//--------------- FFMPEG Headers and Libraries ---------------
extern "C"
{
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
}
int main(int c, char *args[])
{
av_register_all();
AVFormatContext *ctx;
if(avformat_open_input(&ctx,"salam.avi",NULL,NULL)!=0)
return -1;
return 0;
}
It gets compiled & linked fine. But I get this error when I try to run it:
The program has unexpectedly finished
This happens on *avformat_open_input* function. What's the problem? Is it about my code, or it is a problem with my libraries?
Thanks in advance
Finally I found it. The answer is so simple. ctx should be initialized by NULL.
AVFormatContext *ctx = NULL;
Could be a problem with the AVI. Make sure your avi is supported by FFMPEG. use this tool To check what exactly the format is and look up the FFMPEG library help/support to see if the format is supported or not.
Related
I am a beginner to cuda, c++ and I am trying to move openssl sha1 cpu code to cuda c,but I ran into a weired problem.
here is the minimum code that can reproduce the problem.
There are three files in this vs2015 cuda9.0 project. They are main.cpp ,sha1.cu and sha1.h
//main.cpp
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include "openssl\sha.h"
int main()
{
SHA_CTX ctx;
SHA1_Init(&ctx);
return 0;
}
//sha1.h
#ifndef SHA1_H
#define SHA1_H
#include <stdint.h>
#include <cuda_runtime.h>
namespace cudatest {
#ifdef __cplusplus
extern "C" {
#endif
typedef struct
{
uint32_t state[5];
uint32_t count[2];
unsigned char buffer[64];
} SHA1_CTX;
#define SHA_CTX SHA1_CTX
#define SHA_DIGEST_LENGTH 20
__device__ void SHA1_Init(SHA1_CTX * context);
#ifdef __cplusplus
}
#endif
}
#endif /* SHA1_H */
//sha1.cu
#include <cuda_runtime.h>
#include "sha1.h"
namespace cudatest {
__device__ void SHA1_Init(SHA1_CTX * context)
{
}
}
The main.cpp uses C/C++ compiler and sha1.cu uses CUDA C/C++
And I add openssl headers into the AdditionalIncludeDirectories,set directory which contains ssleay32.lib and libeay32.lib to library path,set AdditionalDependencies with ssleay32.lib, libeay32.lib .
Then the project built with no error and no warning. But when I run it
or debug it,I found the function SHA1_Init runs into device code and
the program crashed immediately.
why the compiler linked function SHA1_Init with the cuda device
SHA1_Init implement which has a namespace cudatest wrapped instead
of a ssleay32.lib, libeay32.lib CPU implement?
OK,I found the problem.I shouldn't use extern "C" in a c++ namespace.It make the function visiable to the global namespace. if you define another c SHA1_Init function in a .cpp file ,the linker will complain.But if another SHA1_Init is in a openssl lib,the vs C/C++ linker warnned nothing but linked to the cuda implement.
I have built the LLVM using CMake using VS 2012 in keeping with documentation. I am trying to build a toy compiler with flex, bison and LLVM. The final stage of my compiler my main class looks like this:
#include <iostream>
#include "codegen.h"
#include "node.h"
#include "llvm/Target/Targetmachine.h"
using namespace std;
extern int yyparse();
extern NBlock* programBlock;
void createCoreFunctions(CodeGenContext& context);
int main(int argc, char **argv)
{
yyparse();
std::cout << programBlock << endl;
InitializeNativeTarget();
CodeGenContext context;
createCoreFunctions(context);
context.generateCode(*programBlock);
context.runCode();
return 0;
}
As stated in my previous post LLVM 3.4 linker errors in VS 2012. To workaround the solution I manually added the x86 files I was missing (taking clue from the errors). I ended up adding the following to the main:
#include "llvm-3.4/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.h"
#include "llvm-3.4/lib/Target/X86/InstPrinter/X86ATTInstPrinter.h"
#include "llvm-3.4/lib/Target/X86/InstPrinter/X86IntelInstPrinter.h"
#include "X86MCAsmInfo.h"
#include "llvm/ADT/Triple.h"
#include "llvm/MC/MCCodeGenInfo.h"
#include "llvm/MC/MCInstrAnalysis.h"
#include "llvm/MC/MCInstrInfo.h"
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/MC/MachineLocation.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/TargetRegistry.h"
#include "X86GenRegisterInfo.inc"
#include "X86GenInstrInfo.inc"
#include "X86GenSubtargetInfo.inc"
But I noticed that the following are missing from my system:
"X86MCAsmInfo.h"
"X86GenRegisterInfo.inc"
"X86GenInstrInfo.inc"
"X86GenSubtargetInfo.inc"
I looked through the online documentation but I am a beginner on the topic, most of it did not make too much sense to me. I would appreciate if someone could guide me or point me to the right tutorial which gives me a better understanding of what I am doing wrong here.
I was looking for a native API access in GLFW3 documentation to get HWND but it's not in my GLFW/glfw3.h file. Is there any #define's to be able to find it by compiler? I can't also find it manually in the file itself using text-finder, so how can I get it?
PS. I can't tag glfw3.
Edit:
Code:
#define GLFW_INCLUDE_GLU
#define GLFW_EXPOSE_NATIVE_WGL
#define GLFW_EXPOSE_NATIVE_WIN32
#include <GL/GLFW/glfw3native.h>
#include <GL/GLFW/glfw3.h>
#include <ctime>
#include <cstdlib>
...
int main()
{
//glfw setup
...
//bla bla bla
...
//all I want to do is to call this one
ScreenToClient( glfwGetWin32Window(window), &point);
}
After getting confused by your problems I tried it my self and I think the include order is your problem. A minimal code example that mimics on Linux what you try to do on Windows compiles and works as intended:
#define GLFW_EXPOSE_NATIVE_X11
#define GLFW_EXPOSE_NATIVE_GLX
#include <GLFW/glfw3.h>
#include <GLFW/glfw3native.h>
int main (int argc, char ** argv)
{
glfwInit();
GLFWwindow* window = glfwCreateWindow (256, 256, "GLFW", nullptr, nullptr);
glfwGetX11Window(window);
glfwTerminate();
return 0;
}
EDIT: Added the incovation of glfwTerminate() for proper clean-up. Please note, of course there should be appropriate error checking taking place, but for the purpose of demonstrating a minimal example, the above is sufficient.
I'm desperately trying to access a DLL supplied with some hardware. I have the DLL, the LIB file and the headers for the DLL.
I first tried using C# but failed due to the large data structures that are passed around. I got the functions called but the values in the structures that are modified are not correct.
I then thought about writing a wrapper class in C++ and use this as a library for C#. But again here I can call the function but if I tested an signed long that is passed it is "1072955392l" instead of "-1l".
I then just renamed the cpp file to ".c" and compiled it again. Now I get the correct value.
Are there some differences in the datatypes from C to C++?
The functions for the LIb in the supplied include file are declared like that:
_declspec (dllimport) long ResetControl(Registers* regs);
I compile using VS2013:
cl test.cpp /link test.lib
cl test.c /link test.lib
The cpp file and c file are the same unless I needed to include #include for the cpp and wrap the dll include header in
extern "C"
{
#include "test.h"
}
The test.c file looks like:
//#include <windows.h>
#include <stdlib.h>
#include <malloc.h>
#include <stdio.h>
#include <math.h>
#include "test.h"
int main (int argc, char **argv)
{
Registers Regs;
Reset (&Regs);
printf ("Value: %dl\n\r", Regs.Product);
return 0;
}
The C++ file:
#include <windows.h>
#include <stdlib.h>
#include <malloc.h>
#include <stdio.h>
#include <math.h>
extern "C"
{
#include "test.h"
}
int main (int argc, char **argv)
{
Registers Regs;
Reset (&Regs);
printf ("Value: %dl\n\r", Regs.Product);
return 0;
}
Both compile, but the result of printing Regs.Products is different:
C: -1l
C++: 1072955392l
What am I doing wrong here?
I saw somewhere that there is a matter of aligning to 4 bytes while compiling the client of the DLL.
However have a look to those pages:
http://www.codeproject.com/Articles/21/Beginner-s-Tutorial-Calling-Visual-Basic-ActiveX-D
http://www.codeproject.com/Articles/6242/Step-by-Step-Calling-C-DLLs-from-VC-and-VB-Part
Alexandre
I'm completely new to C++, but I have created a minor program, looking to port the program to other computers, but when I "install" the program I get this error...-static-libgcc -static-libstdc++ missing, is there a file I should be including in the program itself, or is this a library I have to install on each computer? The computers that I expect to run the program will be windows xp. Source code of the file is as follows:
#include <stdlib.h>
#include <windows.h>
#include <direct.h>
#include <string.h>
#include <string>
#include <iostream>
using namespace std;
int main(int argc, const char *argv[])
{
_chdir("C:\\Program Files\\NCHSoftware\\Talk\\");
string number = "start talk.exe -dial " + std::string(argv[1]+4);
system(number.c_str());
exit;
return 0;
}
They are shared lib's that would need to be on the host computer.
To learn how to compile a static version;
See here: http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html
Read the "-static-libgcc" & "-static-libstdc++" sections.