Slient crash when calls to ffmpeg's libav exist - c++

I have a fairly simple example.
#include <iostream>
extern "C"
{
#include <libavutil/opt.h>
#include <libavutil/avutil.h>
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
}
int main(int, char **)
{
AVFormatContext *format = 0; // avformat_alloc_context();
// avformat_open_input(&format, "http://s5radio.ponyvillelive.com:8026/stream.mp3", NULL, NULL);
// avformat_find_stream_info(format, NULL);
std::cout << "Hello, world!" << std::endl;
return 0;
}
I this outputs "Hello, world!" and I can set break points but the moment I uncomment anything calling avformat code the program silently closes with no error and no break points are hit making it impossible to debug.
An example would be changing AVFormatContext *format = 0; to AVFormatContext *format = avformat_alloc_context(); or uncommenting avformat_open_input(&format, "http://s5radio.ponyvillelive.com:8026/stream.mp3", NULL, NULL);. Without breakpoints or errors how do I solve?
Update:
This is what I get from the debugger:
ERROR: Unable to start debugging. Unexpected GDB output from command "-exec-run". During startup program exited with code 0xc0000139.
The program 'path\to\my\project\LibavPlayground.exe' has exited with code 0 (0x00000000).
Update2:
this is my cmake:
cmake_minimum_required(VERSION 3.0.0)
project(LibavPlayground VERSION 0.1.0 LANGUAGES CXX C)
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBAV REQUIRED libavutil libavcodec libavformat)
include_directories(${LIBAV_INCLUDE_DIRS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS -Wno-deprecated-declarations")
include_directories(include PUBLIC)
include_directories(src PRIVATE)
file(GLOB SRC_FILES ${PROJECT_SOURCE_DIR}/src/*.cpp)
add_executable(LibavPlayground ${SRC_FILES})
target_link_libraries(LibavPlayground ${LIBAV_LIBRARIES})
and all the libav* libraries were installed with a single pacman -S mingw-w64-x86_64-ffmpeg command

The current solution is to use WSL instead of MinGw as I don't duplicate the issue in WSL. Although I really hope someone out there has a real solution.

Related

log4cplus ConsoleAppender does not work in container

I'm trying to containerize my application but I'm having trouble getting log4cplus working. Bottom line up front, logging works when running on the host, but not in the container when I'm logging from long running loops. Its seems like a buffer somewhere is not getting flushed. A minimal example follows.
Additionally, removing the long lived loop removes the issue, presumably log4cplus flushes one last time before tearing down. Lengthening the sleep duration did not seem to help.
main.cpp
#include <iostream>
#include <unistd.h>
#include <log4cplus/logger.h>
#include <log4cplus/loggingmacros.h>
#include <log4cplus/configurator.h>
#include <log4cplus/initializer.h>
int main(int argc, char **argv)
{
std::cout << "Sanity Check" << std::endl;
auto log4cplus = ::log4cplus::Initializer();
std::string logconfig("log4cplus_configure.ini");
::log4cplus::PropertyConfigurator::doConfigure(logconfig);
auto logger = ::log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("main"));
while (true) {
LOG4CPLUS_ERROR(logger, "Sleeping...");
// std::cout << "cout sleep..." << std::endl; // uncomment to get log messages working
sleep(1);
}
return 0;
}
log4cplus_configure.ini
log4cplus.rootLogger=INFO, MyConsoleAppender
log4cplus.appender.MyConsoleAppender=log4cplus::ConsoleAppender
log4cplus.appender.MyConsoleAppender.layout=log4cplus::PatternLayout
log4cplus.appender.MyConsoleAppender.layout.ConversionPattern=[%-5p][%d] %m%n
Dockerfile
FROM rockylinux:latest
RUN dnf install -y boost-system
COPY ./build/sandbox /
COPY ./log4cplus_configure.ini /
CMD ["/sandbox"]
CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
set (CMAKE_CXX_STANDARD 17)
# Project executable and library
add_executable(sandbox main.cpp)
target_link_libraries(sandbox
PUBLIC liblog4cplus.a
PUBLIC pthread
PUBLIC boost_system
)
Not sure why, but adding log4cplus.appender.MyConsoleAppender.ImmediateFlush=true to log4cplus_configure.ini solved my issue.

Why won't music play using SDL

#include<iostream>
#include <SDL_mixer.h>
#include <SDL.h>
using namespace std;
int main(int argc, char* argv[])
{
SDL_Init(SDL_INIT_AUDIO);
if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0)
{
cout << "Error: " << Mix_GetError() << std::endl;
}
Mix_Music* song = Mix_LoadMUS("sample.wav");
Mix_PlayMusic(song, 1);
Mix_FreeMusic(song);
song = nullptr;
Mix_Quit();
SDL_Quit();
return 0;
}
I am trying to play a simple song, that I converted to WAV. It is located within the program's folder. I didn't get any errors/warnings when compling and the libraries seem to be linked correctly. On failure, loadMUS returns NULL (which isn't the case) and PlayMusic returns -1 upon failure (which again isn't the case). Yet, when I run the program nothing is heard. This is my first time working with SDL.
To just play a wave file this sample will work with SDL2:
#include <SDL.h>
#include <SDL_audio.h>
int main() {
SDL_Init(SDL_INIT_AUDIO);
SDL_AudioSpec spec{};
Uint8 *audio_buf{};
Uint32 audio_len{};
SDL_LoadWAV("path_to.wav", &spec, &audio_buf, &audio_len);
SDL_AudioSpec ob_spec{};
auto device = SDL_OpenAudioDevice(NULL, 0, &spec, &ob_spec, SDL_AUDIO_ALLOW_ANY_CHANGE);
SDL_QueueAudio(device, audio_buf, audio_len);
SDL_PauseAudioDevice(device, 0);
SDL_Delay(5000);
SDL_CloseAudioDevice(device);
SDL_FreeWAV(audio_buf);
SDL_QuitSubSystem(SDL_INIT_AUDIO);
}
BTW to link easy to SDL2 just use CMake with
cmake_minimum_required(VERSION 3.19)
project(sample_sdl VERSION 1.0)
find_package(SDL2 REQUIRED)
add_executable(${PROJECT_NAME} src/main.cpp)
set_property(TARGET ${PROJECT_NAME} PROPERTY LINKER_LANGUAGE CXX)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 20)
target_link_libraries(${PROJECT_NAME} PRIVATE SDL2::SDL2 SDL2::SDL2main)

allegro not working with clion (0xC000007B)

so I've hit a dead end, I'm simplying trying to run the following:
main.cpp:
#include <iostream>
#include <allegro5/allegro.h>
int main(int argc, char **argv) {
std::cout << "Hello, World!" << std::endl;
al_init();
std::cout << "hi" << std::endl;
return 0;
}
CMakeList.txt:
cmake_minimum_required(VERSION 3.6)
project(allegro_test)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
SET(ALLEGRO_ROOT C:/Users/duck-/workspace/cpp/recources/allegro/)
INCLUDE_DIRECTORIES( ${ALLEGRO_ROOT}/include )
LINK_DIRECTORIES( ${ALLEGRO_ROOT}/lib)
add_executable(allegro_test ${SOURCE_FILES})
TARGET_INCLUDE_DIRECTORIES(allegro_test PUBLIC ${ALLEGRO_ROOT})
TARGET_LINK_LIBRARIES(allegro_test allegro)
output:
"C:\Users\duck-\.CLion2016.2\system\cmake\generated\allegro test-50fbd97d\50fbd97d\Debug\allegro_test.exe"
Process finished with exit code -1073741701 (0xC000007B)
I'm using allegro-mingw-gcc6.2.0-x64-dynamic-5.2.2.zip from here and have copyied allegro-5.2.dll, cygintl-1.dll & cygintl-2.dll to
C:\Users\duck-.CLion2016.2\system\cmake\generated\allegro test-50fbd97d\50fbd97d\Debug\
where the program's executed. I've installed .NET Framework 4.6.2. Am I missing something? cheers in advance.
Since you are building the program in a Debug configuration, you'll need to include allegro-debug-5.2.dll, and not just allegro-5.2.dll.

ITK compilation with cmake

I tried to compile a simple helloWord C++ program with cmake using the ITK library. However I have some difficulties to link with the ITK library and my program doesn't work.
I put my program in the attachment.
helloWorld programme
CMakeLists.txt :
project(HelloWorld)
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
add_executable(HelloWorld HelloWorld.cxx)
target_link_libraries(HelloWorld ${ITK_LIBRAIRIES})
HelloWorld.cxx :
#include "itkImage.h"
#include <iostream>
int main()
{
typedef itk::Image< unsigned short, 3 > ImageType;
ImageType::Pointer image = ImageType::New();
std::cout <<"ITK Hello World !"<< std::endl;
return 0 ;
}
target_link_libraries(HelloWorld ${ITK_LIBRAIRIES})
should be
target_link_libraries(HelloWorld ${ITK_LIBRARIES})

C++ OpenGL GLEW Static Library on Windows 7 MSVC2012

I am attempting to Compile a simple OpenGL program on windows with statically linked glew32mxsd.lib... I am also working with glfw and if I compile without glew everything works.
I Downloaded the glew src and build the static mx debug library from source. I then copied the resulting glew32mxsd.lib file to my project directory. I am using cmake so my cmake code appears as follows.
SET (GLEW_VERSION 1.9.0)
SET (GLEW_DIRECTORY ${EXTERNAL_LIBS}/glew/${GLEW_VERSION})
SET (GLEW_INCLUDES ${GLEW_DIRECTORY}/include)
SET (GLEW_LIBS ${GLEW_DIRECTORY}/win/${SYSTEM_ARC}/lib)
INCLUDE_DIRECTORIES (${GLEW_INCLUDES})
ADD_EXECUTABLE (myproject ${HEADER_FILES} ${SOURCE_FILES})
TARGET_LINK_LIBRARIES(engine OpenGL32.lib)
TARGET_LINK_LIBRARIES(engine ${GLEW_LIBS}/glew32mxsd.lib)
Also in my source I am using the following in my header
#define GLEW_STATIC
#define GLEW_MX
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#ifdef WIN32
#include <GL/wglew.h>
#endif
//-----------------------------------------------------------------
static GLEWContext *glewGetContext()
{
return nullptr;
}
Everything compiles and links without any errors but...
When I run the program I get a memory access error. The call stack is
engine.exe!glewContextInit(GLEWContextStruct * ctx) Line 8912 C
engine.exe!cext::graphics::internal::WindowManager::initGLExtentions() Line 204 C++
engine.exe!cext::graphics::WindowManager::initGLExtentions() Line 273 C++
engine.exe!main(int argc, char * * argv) Line 363 C++
engine.exe!__tmainCRTStartup() Line 536 C
engine.exe!mainCRTStartup() Line 377 C
And looking at line 8912 in glew.c the following line is revealed
CONST_CAST(GLEW_VERSION_4_3) = ( major > 4 ) || ( major == 4 && minor >= 3 ) ? GL_TRUE : GL_FALSE;
My glewInit looks like the following
void initGLExtentions()
{
glewExperimental = true;
GLenum err = glewInit();
if (GLEW_OK != err)
{
printf("Error: %s\n",glewGetErrorString(err));
}
printf("Status: Using GLEW %s\n",glewGetString(GLEW_VERSION));
if (!GLEW_ARB_vertex_buffer_object)
{
printf("VBO not supported\n");
exit(EXIT_FAILURE);
}
}
...
glfwWindow *window = makeWindow(options,hints);
if (!window)
{
fprintf( stderr, "Failed to open GLFW window\n" );
glfwTerminate();
exit( EXIT_FAILURE );
}
glfwMakeContextCurrent(window);
initGLExtentions();
Using the same code on Mac works without a problem which leads me to believe that it is something to do with the static lib. However even after following all the instructions on the glew website I must be missing something still.
Edit: Additional Information
I ran dependency walker on my application after reading about it in another thread. Running dependency walker on my exe file produces the following missing files
API-MS-WIN-CORE-COM-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-ERROR-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-ROBUFFER-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-STRING-L1-1-0.DLL
API-MS-WIN-SHCORE-SCALING-L1-1-0.DLL
DCOMP.DLL
GPSVC.DLL
IESHIMS.DLL
These are called from the USER32.DLL. Are these related to the glew.lib or wglew.lib in anyway?