Skip to content

Instantly share code, notes, and snippets.

@dradtke
Created May 5, 2014 15:12
Show Gist options
  • Select an option

  • Save dradtke/9ccdd5e4a125114cd356 to your computer and use it in GitHub Desktop.

Select an option

Save dradtke/9ccdd5e4a125114cd356 to your computer and use it in GitHub Desktop.
Testing cgo with Allegro 5 on Windows.
// Built with:
// gcc -I/Opt/allegro-5.0.10-mingw-4.7.0/include -m32 -L/Opt/allegro-5.0.10-mingw-4.7.0/bin -lallegro-5.0.10-monolith-md hello-allegro.c
//
#include <stdio.h>
#include <allegro5/allegro.h>
int main(void)
{
al_init();
uint32_t version = al_get_allegro_version();
int major = version >> 24;
int minor = (version >> 16) & 255;
int revision = (version >> 8) & 255;
int release = version & 255;
printf("Allegro version: %d.%d.%d[%d]\n", major, minor, revision, release);
return 0;
}
package main
// #cgo CFLAGS: -I/Opt/allegro-5.0.10-mingw-4.7.0/include -m32
// #cgo LDFLAGS: -L/Opt/allegro-5.0.10-mingw-4.7.0/bin -lallegro-5.0.10-monolith-md
// #include <allegro5/allegro.h>
//
// void _al_init() {
// al_init();
// }
import "C"
import "fmt"
func version() (major, minor, revision, release uint8) {
version := uint32(C.al_get_allegro_version())
major = uint8(version >> 24)
minor = uint8((version >> 16) & 255)
revision = uint8((version >> 8) & 255)
release = uint8(version & 255)
return
}
func main() {
C._al_init()
major, minor, revision, release := version()
fmt.Printf("Allegro version: %d.%d.%d[%d]\n", major, minor, revision, release)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment