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?
Related
I compiled the FFMPEG source file myself and got the header and library files in an include and bin folder respectively, the target platform is Windows 10. I also setup my cmakelist.txt to find and include both the library and header files. The application finds the path or so it seems because during compilation I get a "LNK2019 error unresolved external symbol avformat_alloc_context referenced in function main". Below is an extract from my cmake list; I will like to note that I got the .lib and .dll versions of the library hence the approach below based on the book "professional cmake" and other stackflow examples.
ProjectDir/AudMan/cmakelist.txt
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH};PATH-TO-INCLUDES;PATH-TO-LIBRARY)
find_path(AVFORMAT_INCLUDE_DIR libavformat/avformat.h)
find_library(AVFORMAT_LIBRARY avformat)
add_library(ffmpegHeaders INTERFACE)
target_include_directories(ffmpegHeaders INTERFACE ${AVFORMAT_INCLUDE_DIR})
ProjectDir/cmakelist.txt
set(Rapid_Prefix PATH-TO-LIBRARY)
add_library(AVformat SHARED IMPORTED)
set_target_properties(AVformat PROPERTIES IMPORTED_LOCATION ${Rapid_Prefix}/avformat-59.dll IMPORTED_IMPLIB ${AVFORMAT_LIBRARY})
target_link_libraries(App_target PRIVATE AVformat)
A sample of the codes is this
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
}
int main()
{
AVFormatContext* format = avformat_alloc_context();
if (avformat_open_input(&format, R"(\test.m4a)", NULL, NULL) != 0) {
fprintf(stderr, "Could not open file '%s'\n", R"(\test.m4a)");
return -1;
}
if (avformat_find_stream_info(format, NULL) < 0) {
fprintf(stderr, "Could not retrieve stream info from file '%s'\n", R"(test.m4a)");
return -1;
}
return 0;
}
I have been at it for about five days and will appreciate any help I can get.
I am trying to create make a purple window using glfw window library and with bgfx C++ on arch linux like below:
but it gives out the error:
X Error of failed request: GLXBadDrawable
Major opcode of failed request: 152 (GLX)
Minor opcode of failed request: 11 (X_GLXSwapBuffers)
Serial number of failed request: 33
Current serial number in output stream: 33
my main.cpp:
#include "main.h"
int main(int, char**) {
glfwInit();
GLFWwindow* window = glfwCreateWindow(WNDW_WIDTH, WNDW_HEIGHT, "Hello, bgfx!", NULL, NULL);
bgfx::Init bgfxInit;
bgfxInit.type = bgfx::RendererType::Count; // Automatically choose a renderer.
bgfxInit.resolution.width = WNDW_WIDTH;
bgfxInit.resolution.height = WNDW_HEIGHT;
bgfxInit.resolution.reset = BGFX_RESET_VSYNC;
bgfx::init(bgfxInit);
bgfx::setViewClear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x443355FF, 1.0f, 0);
bgfx::setViewRect(0, 0, 0, WNDW_WIDTH, WNDW_HEIGHT);
unsigned int counter = 0;
while(true) {
bgfx::frame();
counter++;
}
return 0;
}
main.h:
#include <iostream>
#define BX_CONFIG_DEBUG
#define BGFX_P_H_HEADER_GUARD
#include "libs/bgfx/include/bgfx/bgfx.h"
#include "libs/bgfx/include/bgfx/platform.h"
#include <GLFW/glfw3.h>
#define GLFW_EXPOSE_NATIVE_X11
#include <GLFW/glfw3native.h>
int WNDW_WIDTH=1600;
int WNDW_HEIGHT =900;
here i included my glfw and bgfx header files
my CMakefile.txt:
cmake_minimum_required(VERSION 3.0.0)
project(bgfx_engine VERSION 0.1.0)
add_executable(bgfx_engine main.cpp)
target_link_libraries(${PROJECT_NAME} GL X11 glfw)
target_link_directories(${PROJECT_NAME} PRIVATE ./libs/bgfx/.build/linux64_gcc/bin/)
target_link_libraries(${PROJECT_NAME} bgfxRelease bimgRelease bxRelease)
I dont know what that error means so i am unable to solve it.
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.
I am trying to run a simple example to set up EGL context in a docker container. However, I keep getting this error message :
Detected 0 devices
terminate called after throwing an instance of 'std::runtime_error'
what(): EGL error 0x300c at eglGetDisplay
Aborted
Basically, eglQueryDevicesEXT returns 0, and eglGetPlatformDisplayEXT returns error code 0x300c (EGL_BAD_PARAMETER) .
I have tried on :
Ubuntu 16.04 docker on a Macbook Pro
Ubuntu 16.04 docker on a Ubuntu 16.04 server with Nvidia GPU
On these docker environments, I installed openGL and ELG using apt-get install libgl1-mesa-dev and apt-get install libegl1-mesa-dev. CMake can find the components GL::GL and EGL::EGL.
I have tried link to libEGL.so both manually and using find_package in CMake.
This is driving me crazy! I can't figure out why EGL can't detect devices? How can I resolve this error?
Here is my full code. I have also tried EGLDisplay eglDpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); which gives me the same error. Thanks!
#include <EGL/egl.h>
#include <EGL/eglext.h>
void assertEGLError(const std::string& msg) {
EGLint error = eglGetError();
if (error != EGL_SUCCESS) {
std::stringstream s;
s << "EGL error 0x" << std::hex << error << " at " << msg;
throw std::runtime_error(s.str());
}
}
int main(int argc, char *argv[])
{
// 1. Initialize EGL
// EGLDisplay eglDpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
int deviceID = 0; // TODO hardcode
EGLDisplay eglDpy;
EGLConfig config;
EGLContext context;
EGLint num_config;
static const int MAX_DEVICES = 16;
EGLDeviceEXT eglDevs[MAX_DEVICES];
EGLint numDevices;
PFNEGLQUERYDEVICESEXTPROC eglQueryDevicesEXT =
(PFNEGLQUERYDEVICESEXTPROC)eglGetProcAddress("eglQueryDevicesEXT");
eglQueryDevicesEXT(MAX_DEVICES, eglDevs, &numDevices);
printf("Detected %d devices\n", numDevices);
PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT =
(PFNEGLGETPLATFORMDISPLAYEXTPROC)eglGetProcAddress("eglGetPlatformDisplayEXT");
// Choose device by deviceID
eglDpy = eglGetPlatformDisplayEXT(EGL_PLATFORM_DEVICE_EXT, eglDevs[deviceID], nullptr);
assertEGLError("eglGetDisplay");
return 0;
}
OMG I finally solved this problem. Turned out I was linking to the wrong library on the server.
I found the answer in this post: https://forums.developer.nvidia.com/t/problem-with-opengl-visualization-without-an-x-server/73204/15
The key is to link to the libraries in /usr/lib/nvidia-410/, not the system default /usr/local/lib/x86_64-linux-gnu/libEGL.so
The new CMake that works:
target_link_libraries(sandbox PRIVATE /usr/lib/nvidia-410/libEGL.so)
target_link_libraries(sandbox PRIVATE /usr/lib/nvidia-410/libGLX.so)
target_link_libraries(sandbox PRIVATE /usr/lib/nvidia-410/libOpenGL.so)
Previously I used CMake's findOpenGL to search for link libraries, which does not work
find_package(OpenGL REQUIRED COMPONENTS OpenGL EGL GLX)
include_directories(${OPENGL_INCLUDE_DIRS})
if(OPENGL_FOUND)
message("Found OpenGL in the current environment!")
else()
message("Error: No OpenGL found.")
endif()
message("OpenGL include dirs" )
message("${OPENGL_INCLUDE_DIR}")
message("EGL include dirs" )
message("${OPENGL_EGL_INCLUDE_DIRS}")
if (OpenGL_EGL_FOUND)
message("EGL Found!")
else()
message("EGL Not Found!")
endif()
message(${OPENGL_egl_LIBRARY})
message(${OPENGL_glx_LIBRARY})
message(${OPENGL_opengl_LIBRARY}
Note again this does not work !!
/usr/local/lib/x86_64-linux-gnu/libEGL.so
/usr/local/lib/x86_64-linux-gnu/libGLX.so
/usr/local/lib/x86_64-linux-gnu/libOpenGL.so
I am using Xcode 11.4 on MacOS Catalina 10.15.3
I use HomeBrew to install SDL2 by Terminal:
brew install sdl2
and then, I open Xcode, create new project named SDL2Tutorial to test the library.
I changed the header search path to
/usr/local/include
and added /usr/local/cellar/sdl2/2.0.12_1/lib/libSDL2-2.0.0.dylib to Link Binary With Library
In main.cpp I wrote code like this
#include <iostream>
#include <SDL2/SDL.h>
int main(int argc, char * argv[]) {
// insert code here...
if (SDL_Init( SDL_INIT_EVERYTHING ) < 0)
{
std::cout << "Error: " << SDL_GetError() << std::endl;
}
return EXIT_SUCCESS;
}
and there are a lot of errors appeared including:
2020-04-02 17:03:41.767966+0700 SDL2Tutorial[829:23149] Metal API Validation Enable
2020-04-02 17:03:41.799979+0700 SDL2Tutorial[829:23443] flock failed to lock maps file: errno = 35
2020-04-02 17:03:41.800445+0700 SDL2Tutorial[829:23443] flock failed to lock maps file: errno = 35
2020-04-02 17:03:41.848181+0700 SDL2Tutorial[829:23149] [plugin] AddInstanceForFactory: No factory registered for id F8BB1C28-BAE8-11D6-9C31-00039315CD46
2020-04-02 17:03:41.875838+0700 SDL2Tutorial[829:23149] HALC_ShellDriverPlugIn::Open: Can't get a pointer to the Open routine
2020-04-02 17:03:41.876282+0700 SDL2Tutorial[829:23149] HALC_ShellDriverPlugIn::Open: Can't get a pointer to the Open routine
Did I miss any step of setting up the library and how can I solve all of the errors?