MAC 10.7 : Where is the gl.h file? [duplicate] - c

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
FreeGLUT on Mac OS X Lion
First quizz : could anyone just please explain me why am I not able to find the gl.h file anywhere on my mac ?! If this question can simply be answered maybe you do not even have to read the rest, but I couldn't find any answer on the web to that one (after hours of research), except the famous "it's integrated into the os" or something like that.
My problem In detail:
I am having an issue with the compilation of a .c file using OpenGL. Ihave browsed the web for hours without finding any solution. Here is the problem :
For those who know this software, I am using Webots (a robot simulation software) and I would like to implement a physic plugin. I copied the code from an already existing (and working) plugin, just to try it out. I am compiling with webots, which uses a gcc (I had to install a gcc compiler since it doesn't come with Xcode anymore).
Now, the problem is that the .c file includes a "physics.h" header which includes the OpenGL/gl.h file and I then get the error : "OpenGL/gl.h . no such file or directoy".
Now I've tried to many things :
making a search for gl.h : it seems it doean't exist (I can't find it, either manually or with the finder search function)
replacing the include OpenGL/gl.h by GLUT/glut.h : I get the error "gl.h and glu.h no such fil or directory" since their included in the glut.h
linking the gl libraries in the makefile and the frameworks as well
Probably all the combination of these, using absolute or relative path !
Since OpenGL and GLUT are supposed to be natively installed with OS (I am on using Lion 10.7.5) I guess every needed file should be there. And for this reaon I cannot find a way to download this supposedely missing file...
Moreover a coworker of mine tried and successfully compiled it on linux ! Linux is a great platform but I still love my mac, so please let me hope there is another solution than to change for linux !!!
I think my problem lies either in the Makefile or in the physic.h file, so here they are :
Physic.h:
#ifndef PHYSICS_H
#define PHYSICS_H
#include <ode/ode.h>
#ifdef WIN32
#include <windows.h>
#endif
#ifndef MACOS
#include <GL/gl.h>
#else
#include <OpenGL/gl.h>
#endif
/* callback functions to be implemented in your physics plugin */
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _MSC_VER
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT
#endif
DLLEXPORT void webots_physics_init(dWorldID,dSpaceID,dJointGroupID);
DLLEXPORT int webots_physics_collide(dGeomID,dGeomID);
DLLEXPORT void webots_physics_step();
DLLEXPORT void webots_physics_step_end();
DLLEXPORT void webots_physics_cleanup();
DLLEXPORT void webots_physics_draw();
DLLEXPORT void webots_physics_predraw();
/* utility functions to be used in your callback functions */
#ifndef LINUX
extern dGeomID (*dWebotsGetGeomFromDEFProc)(const char *);
extern dBodyID (*dWebotsGetBodyFromDEFProc)(const char *);
extern void (*dWebotsSendProc)(int,const void *,int);
extern void* (*dWebotsReceiveProc)(int *);
extern void (*dWebotsConsolePrintfProc)(const char *, ...);
extern double (*dWebotsGetTimeProc)();
#define dWebotsGetGeomFromDEF(DEFName) (*dWebotsGetGeomFromDEFProc)(DEFName)
#define dWebotsGetBodyFromDEF(DEFName) (*dWebotsGetBodyFromDEFProc)(DEFName)
#define dWebotsSend(channel,buff,size) (*dWebotsSendProc)(channel,buff,size)
#define dWebotsReceive(size_ptr) (*dWebotsReceiveProc)(size_ptr)
#if defined(__VISUALC__) || defined (_MSC_VER) || defined(__BORLANDC__)
#define dWebotsConsolePrintf(format, ...) (*dWebotsConsolePrintfProc)(format, __VA_ARGS__)
#else
#define dWebotsConsolePrintf(format, ...) (*dWebotsConsolePrintfProc)(format, ## __VA_ARGS__)
#endif
#define dWebotsGetTime() (*dWebotsGetTimeProc)()
#else
dGeomID dWebotsGetGeomFromDEF(const char *DEFName);
dBodyID dWebotsGetBodyFromDEF(const char *DEFName);
void dWebotsSend(int channel,const void *buffer,int size);
void *dWebotsReceive(int *size);
void dWebotsConsolePrintf(const char *format, ...);
double dWebotsGetTime();
#endif
#ifdef __cplusplus
}
#endif
#endif /* PHYSICS_H */
Makefile:
###
### Standard Makefile for Webots physics plugins
###
### Supported platforms: Windows, Mac OS X, Linux
### Supported languages: C, C++
###
### Authors: Olivier Michel - www.cyberbotics.com
### Revised: Yvan Bourquin - September 30th, 2009.
###
### Uncomment the variables to customize the Makefile
### -----C Sources-----
###
### if your plugin uses several C source files:
C_SOURCES = my_contact_p_physics.c
### -----C++ Sources-----
###
### if your plugin uses several C++ source files:
# CPP_SOURCES = my_plugin.cpp my_clever_algo.cpp my_graphics.cpp
### or
# CC_SOURCES = my_plugin.cc my_clever_algo.cc my_graphics.cc
FRAMEWORK = -framework OpenGL -framework GLUT
### -----Options-----
###
### if special CFLAGS are necessary, for example to set optimization level or
### to find include files:
#CFLAGS=-O3 -I/System/Library/Frameworks/OpenGL.framework
###
### if your plugin needs additional libraries:
LIBRARIES=-L/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries -llibGL -llibGLU
### Do not modify: this includes Webots global Makefile.include
space :=
space +=
WEBOTS_HOME_PATH=$(subst $(space),\ ,$(strip $(subst \,/,$(WEBOTS_HOME))))
include $(WEBOTS_HOME_PATH)/resources/projects/default/plugins/physics/Makefile.include
P.S: In the "my_contact_p_physics.c" (the .c file I am trying so hard to compile) I simply include a ODE/ode.h file and the physics.h file with absolute path. I cannot compile directy in the terminal because of the ODE which "integrated" into webots, reason why I compile in webots directly.

The gl.h is there, alright - Just in /System/Library/Frameworks/OpenGL.framework/Headers. Either use -framework OpenGL, or add -I /System/Library/Frameworks/OpenGL.framework/Headers to the compiler flags. Assuming your file is there (which it is, by default), you should find it, and all should work!

Related

With macros, how to compile a DLL and a static lib from the exact same code?

I plan on building several libraries following the FIPS standards (hashing, encryption). I want to have several batch/bash scripts that will automate the building process of these libraries for every desktop platforms (Windows, Mac, Linux). I plan on using MinGW's port of gcc on Windows and simply gcc on Linux or Mac.
My code for the library is the following:
hash.h
#ifndef HASHH
#define HASHH
#ifdef STATIC
#define ADDAPI
#define ADDCALL
#define EXTERN extern
#else
#define EXTERN
#ifdef _WIN32
#ifdef BUILD
#define ADDAPI __declspec(dllexport)
#else
#define ADDAPI __declspec(dllimport)
#endif
#define ADDCALL __cdecl
#else
#define ADDAPI
#define ADDCALL
#endif
#endif
/*** The sha3-256 hash function.
#param buffer The buffer containing the data to be hashed.
#param length The length of the buffer.
#param digest The hash of the data in buffer.
*/
ADDAPI EXTERN int ADDCALL sha3_256(unsigned char* buf, unsigned long len, unsigned char* digest);
#endif
hash.c
#include "hash.h"
int sha3_256(unsigned char* buf, unsigned long len, unsigned char* digest){
return len * 2;
}
For DLL target on Windows I do:
gcc -c -D BUILD source\hash.c -oobjects\hash.o
ld -s -shared objects\hash.o -ohash.dll
For static target I do:
gcc -c -D STATIC source\hash.c -oobjects\hash.o
ar rcs hash.lib objects\hash.o
Everything works fine for building but when I use the header in a program the ADDAPI and ADDCALL macros are never defined for static building. This is due to the STATIC macro never initialized. I would like that this same header works for both building and using in client apps. I would also like that the macros allow to build both for dll target than for static lib target without the client having to pass a macro on the command line for it to work.
Do you have any idea if this is possible?
If it is, how would you go about doing this?
With the above code both building static and dll works but for client only dll works because for static I need to pass the STATIC macro on the command line. I want an option to prevent that.

How to create a DLL and use it with Eclipse for C

I created a DLL in eclipse like so:
created a C-Project -> shared library (MinGW) -> Name: testdll
created a header- and a source-file with an simple TestFunction
The source-file is like:
#include <stdio.h>
#include "test.h"
void write(){
printf("hallo von der dll\n");
}
Then I build it and under Debug a libtestdll.dll was created.
That looked good for me so far.
Now I created a C-Hello World-Project called usedll.
The file looks like this:
#include <stdio.h>
#include <stdlib.h>
#include "test.h"
int main(void) {
puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */
write();
printf("done\n");
return EXIT_SUCCESS;
}
I created a lib-Folder under project usedll. I copied the libtestdll.dll and the test.h into this folder.
With a right-click on project usedll -> Properties -> C++Build -> Settings -> GCC C Compiler -> Includes -> add (added the lib-Folder from same project usedll)
Then under MinGW C Linker -> Libraries -> Libraries - I added the string libdll
and under Library Search Path I added the lib-folder from the usedll-Project.
The project was now build without errors, but when I executed it, the write-function does not produced any output.
Does someone see what I do wrong ?
Please read this ...
http://www.mingw.org/wiki/sampledll
I'll add a snippet below, but I feel you might not have exported your function, reading the above will explain how to do this (using MinGW).
( This snippet has been taken directly from the above webpage )
#ifdef BUILDING_EXAMPLE_DLL
#define EXAMPLE_DLL __declspec(dllexport)
#else
#define EXAMPLE_DLL __declspec(dllimport)
#endif
void __stdcall EXAMPLE_DLL hello(const char *s);
Please take note of the use of __declspec(dllexport) and __declspec(dllimport)

Error compiling metismex in matlab r2013

I have downloaded and succesfully compiled metis 5.0.2 in a win7 x64 pc
and trying to compile metismex.
I compiled metis with Visual Studio 11 (2012) and using the same compiler from within matlab.
After a lot of experimentation with a ton of errors (mainly owed to paths issues from within the libraries) I have reached a point where I dont know how to proceed, since my knowledge on c and c++ is pretty basic.
So, here's the error :
../GKlib/mat_libs/.\stddef.h(16) : error C2054: expected '(' to follow '_SIZE_TYPE__'
../GKlib/mat_libs/.\stddef.h(19) : error C2085: '_WCHAR_TYPE__' : not in formal parameter list
I found out about the inline functions etc, but since the error is within a library and dont exactly know what I should be doing, here I am. So, the error code is produced here :
typedef __SIZE_TYPE__ size_t;
#ifndef __cplusplus
typedef __WCHAR_TYPE__ wchar_t;
#endif
any suggestions on what I should do without messing it up?
(in case I comment out wchar type, I also have the same error on prtdiff_type)
Thanks in advance
P.S: In case it is needed, here's the whole sttdef.h
/* Copyright 2012 The MathWorks, Inc. */
#ifndef _STDDEF_H
#define _STDDEF_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
# define NULL (0)
#else
# define NULL ((void *)0)
#endif
typedef __SIZE_TYPE__ size_t;
#ifndef __cplusplus
typedef __WCHAR_TYPE__ wchar_t;
#endif
typedef __PTRDIFF_TYPE__ ptrdiff_t;
#if (! defined(__cplusplus)) || (! defined(PST_GNU))
# define offsetof(type, field) ((size_t) &((type *)0)->field)
#else
# define offsetof(type, field) \
(__offsetof__(reinterpret_cast<size_t> \
(&reinterpret_cast<const volatile char &> \
(static_cast<type *>(0)->field))))
#endif
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* _STDDEF_H *
/
Here is a walk-through of what I did. I'm running R2014a with VS2013 on Win8.1 x64.
1) First we compile metis:
Download and extract metis-5.1.0 to some location, say C:\metis-5.1.0
Edit C:\metis-5.1.0\include\metis.h and set #define IDXTYPEWIDTH 64 (for x64 architecture)
Next we generate Visual Studio projects using CMake:
> cd C:\metis-5.1.0
> vsgen -G "Visual Studio 12 2013 Win64"
Before we build the solution, we need to fix a few things first. Some header files are unnecessarily redefining rint function for MSVC (metisbin.h, metislib.h, and gk_arch.h). Remove such lines:
#ifdef __MSC__ /* MSC does not have rint() function */
#define rint(x) ((int)((x)+0.5))
/* MSC does not have INFINITY defined */
#ifndef INFINITY
#define INFINITY FLT_MAX
#endif
#endif
Also in GKlib\gk_externs.h replace all occurrences of __thread with __declspec(thread)
Next open the solution file C:\metis-5.1.0\build\windows\METIS.sln in Visual Stduio, and build ALL_BUILD target (make sure "x64" in "Release" mode is selected).
We are mainly interested in the metis project. Its result should be stored in C:\metis-5.1.0\build\windows\libmetis\Release\metis.lib (a static library).
2) Next we build the MEX-function:
Download metismex and extract it to a folder inside the previous location (C:\metis-5.1.0\metismex-master)
Again we need to fix a few things: first rename metismex.c to metismex.cpp (the C++ compiler is much better than the C compiler in Visual Studio!). Next edit this file and replace: #include <strings.h> with #include <string.h>, and add the following code immediately after it:
#if defined(_WIN32) || defined(_WIN64)
#define snprintf _snprintf
#define vsnprintf _vsnprintf
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
#endif
Finally start MATLAB, and run the following command to compile the MEX-file:
>> cd('C:\metis-5.1.0\metismex-master')
>> mex -O -largeArrayDims -DWIN32 -DMSC -DUSE_GKREGEX -I../GKlib -I../include -I../libmetis metismex.cpp ../build/windows/libmetis/Release/metis.lib
You should now have the final metismex.mexw64
I should say that I know nothing about the library, so I cannot guarantee it gives correct results after all the above modifications. I'm just showing how to get it to compile. The code was written with Linux/OSX in mind, and relies on many POSIX features not intended for Windows. Also the whole 32 vs. 64 bit is a bit messy...

weird c function syntax

I know my C up to this point. I was looking at the source files of PHP I downloaded, and I saw this strange syntax:
PHPAPI int php_printf(const char *format, ...)
{
// code...
}
What does the PHPAPI do before the return type int? I've tried searching all over and I can't understand what this means. Is it a second return type? It can't be because the function does return an int. Maybe it extends to some other struct declared in a header file?
The hard way:
Go to the makefile and add in the line that compiles the sources: -E, by doing so you will see the source cose after the preprocessing phase.
The easy way:
Search all the project for PHPAPI:
find it in php.h:
#ifdef PHP_WIN32
#include "win95nt.h"
# ifdef PHP_EXPORTS
# define PHPAPI __declspec(dllexport)
# else
# define PHPAPI __declspec(dllimport)
# endif
#define PHP_DIR_SEPARATOR '\\'
#else
#define PHPAPI
#define THREAD_LS
#define PHP_DIR_SEPARATOR '/'
#endif
Now what you need to know is what is __declspec(dllexport) and what is __declspec(dllimport)
In the SO thread- What is __declspec and when do I need to use it?
see Alexander Gessler answer:
The canonical examples are __declspec(dllimport) and
__declspec(dllexport), which instruct the linker to import and
export (respectively) a symbol from or to a DLL.
// header
__declspec(dllimport) void foo();
// code - this calls foo() somewhere in a DLL
foo();
(__declspec(..) just wraps up Microsoft's specific stuff - to
achieve compatibility, one would usually wrap it away with macros)

Create a valid shared library in C

I'm doing some test to learn how to create shared library.
The template for shared libraries in Code::Blocks is this
library.c
// The functions contained in this file are pretty dummy
// and are included only as a placeholder. Nevertheless,
// they *will* get included in the shared library if you
// don't remove them :)
//
// Obviously, you 'll have to write yourself the super-duper
// functions to include in the resulting library...
// Also, it's not necessary to write every function in this file.
// Feel free to add more files in this project. They will be
// included in the resulting library.
// A function adding two integers and returning the result
int SampleAddInt(int i1, int i2)
{
return i1 + i2;
}
// A function doing nothing ;)
void SampleFunction1()
{
// insert code here
}
// A function always returning zero
int SampleFunction2()
{
// insert code here
return 0;
}
I tried to compile it, and it compiled without any error or warning. But when i tried to use it with the ctyped.cdll.LoadLibrary("library path.dll") in python 3(that actually should work like the C function), it said that it wasn't a valid win32 application. Both python and code::blocks are 32 bit (code:blocks compile with gcc, and i tryed to use an installed version of mingw on my system, but it gives some error about a missing library) while i'm working on win 7 64bit
Do you know what the problem can be, or if i'm doing something wrong?
EDIT1:
i'm on windows 7 64bit, in the specs file of the compiler is wrote: "Thread model: win32, gcc version 3.4.5 (mingw-vista special r3)"
and i used as command
gcc.exe -shared -o library.dll library.c
in python i used
from ctypes import *
lib = cdll.LoadLibrary("C:\\Users\\Francesco\\Desktop\\C programmi\\Python\\Ctypes DLL\\library.dll")
and the error was
WindowsError: [Error 193] %1 is not a valid Win32 application
i installed both python3.1 and mingw from the binary package and not compiling them on my system
EDIT2:
After reading Marc answer.
main.h
#ifndef __MAIN_H__
#define __MAIN_H__
#include <windows.h>
#ifdef BUILD_DLL
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT __declspec(dllimport)
#endif
#ifdef __cplusplus
extern "C"
{
#endif
DLL_EXPORT int MySimpleSum(int A, int B);
#ifdef __cplusplus
}
#endif
#endif // __MAIN_H__
main.c
#include "main.h"
// a sample exported function
DLL_EXPORT int MySimpleSum(int A, int B)
{
return A+B;
}
compiling options
gcc -c _DBUILD_DLL main.c
gcc -shared -o library.dll main.o -Wl,--out-implib,liblibrary.a
with gcc 4.5.2
still get the same error..
I believe in the windows environment you need to use the __declspec annotation. How to create a shared library and the use of __declspec is described here: DLL Creation in MingW.

Resources