I wrote a test module and I am able to build it using gcc from the command line using this command
gcc -shared -Iheaders/default_fwd_shader_2D.h -framework OpenGL src/default_fwd_shader_2D.c -o test
that comes out fine. When I write my build.gradle file for the same program, I get an error 'clang: error: unknown argument: -framework Opengl'
from this build.gradle file
default_shader(NativeLibrarySpec) {
sources.c {
source {
srcDir "src/core_graphics/default_shader/src"
include "**/*.c"
}
exportedHeaders {
srcDir "src/core_graphics/default_shader/headers"
}
}
binaries.all {
linker.args "-framework openGL"
}
}
I suspect I am doing something wrong since I cannot get gradle to compile this module for me but I was able to use gcc and it compiled fine as a shared and static library.
Although looking at the NM I get this output.
http://imgur.com/yKiiUXo
Those unlinked symbols are the same exact ones that gradle fails on when it tries to build.
What am I doing wrong with this setup? How can I link against opengl? I have the proper headers in my file and all source code lint checks pass w/o any issues.
edit - additional information and a small test program
Just to make sure that I wrote a sample program and compiled it with gcc, it worked as expected. Here’s the code:
#include <stdlib.h>
#include <stdio.h>
#include "SDL2/SDL.h"
#define GL_GLEXT_PROTOTYPES
#include <SDL2/SDL_opengl.h>
int main(int argc, char* argv[])
{
const char* v_shader_srouce; //left out for simplicity
const char* f_shader_source; //
GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexShader, 1, &v_shader_srouce, NULL);
glCompileShader(vertexShader);
GLint success;
GLchar infoLog[512];
glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &success);
if (!success) {
glGetShaderInfoLog(vertexShader, 512, NULL, infoLog);
printf("ERROR VERTEX COMPILATION_FAILED %s\n", infoLog);
}
GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragmentShader, 1, &f_shader_source, NULL);
glCompileShader(fragmentShader);
glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &success);
if (!success) {
glGetShaderInfoLog(vertexShader, 512, NULL, infoLog);
printf("ERROR FRAGMENT COMPILATION_FAILED %s\n", infoLog);
}
GLuint shaderProgram = glCreateProgram();
glAttachShader(shaderProgram, vertexShader);
glAttachShader(shaderProgram, fragmentShader);
glLinkProgram(shaderProgram);
glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success);
if (!success) {
glGetProgramInfoLog(shaderProgram, 512, NULL, infoLog);
printf("ERROR SHADER PROGRAM COMPILATION_FAILED %s\n", infoLog);
}
glDeleteShader(vertexShader);
glDeleteShader(fragmentShader);
glDeleteShader(shaderProgram);
return 0;
}
compiling this code with gcc from the command line like this:
gcc -g -Wall test.c -o test -lSDL2 -framework OpenGL
compiling like that and debugging the program it works just fine.
Leaving off the -framework OpenGL
and I get linking errors just like my gradle project.
When I add the -framework OpenGL to my gradle linker args gradle complains and fails the build.