Skip to content

Instantly share code, notes, and snippets.

@jish

jish/build.sh Secret

Last active November 23, 2016 00:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jish/24734d381fb9a27525b9f91bdfa21c77 to your computer and use it in GitHub Desktop.
Save jish/24734d381fb9a27525b9f91bdfa21c77 to your computer and use it in GitHub Desktop.
GameUpdateAndRender in a separate file causes issues
#!/usr/bin/env bash
mkdir -p build
gcc -framework Cocoa \
-x objective-c \
code/osx_handmade.mm \
-o build/handmade
In file included from code/osx_handmade.mm:3:
code/handmade.h:3:15: warning: function 'GameUpdateAndRender' has internal linkage but is not
defined [-Wundefined-internal]
internal void GameUpdateAndRender();
^
code/osx_handmade.mm:63:3: note: used here
GameUpdateAndRender();
^
1 warning generated.
Undefined symbols for architecture x86_64:
"_GameUpdateAndRender", referenced from:
_main in osx_handmade-4f9411.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [osx] Error 1
#include "handmade.h"
internal void GameUpdateAndRender() {
}
#define internal static
internal void GameUpdateAndRender();
#include <Cocoa/Cocoa.h>
#include "handmade.h"
void OSXInitNSApplication(void)
{
NSApplication *app = [NSApplication sharedApplication];
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
}
void OSXCreateMainMenu() {
NSString* appName = @"Handmade Hero";
NSMenu* menubar = [NSMenu new];
NSMenuItem* appMenuItem = [NSMenuItem new];
[menubar addItem:appMenuItem];
[NSApp setMainMenu:menubar];
NSMenu* appMenu = [NSMenu new];
NSString* fullScreenTitle = @"Toggle Full Screen";
NSMenuItem* fullScreenItem = [[NSMenuItem alloc]
initWithTitle:fullScreenTitle
action:@selector(toggleFullScreen:)
keyEquivalent:@"f"];
[appMenu addItem:fullScreenItem];
NSString* quitTitle = [@"Quit " stringByAppendingString:appName];
NSMenuItem* quitMenuItem = [[NSMenuItem alloc]
initWithTitle:quitTitle
action:@selector(terminate:)
keyEquivalent:@"q"];
[appMenu addItem:quitMenuItem];
[appMenuItem setSubmenu:appMenu];
}
void OSXCreateWindow() {
NSString* appName = @"Handmade Hero";
NSRect initialFrame = NSMakeRect(0, 0, 640, 480);
NSWindow* window = [[NSWindow alloc] initWithContentRect:initialFrame
styleMask:NSTitledWindowMask
backing:NSBackingStoreBuffered
defer:NO];
[window cascadeTopLeftFromPoint:NSMakePoint(20,20)];
[window setBackgroundColor:NSColor.blackColor];
[window setTitle:appName];
[window makeKeyAndOrderFront:nil];
[NSApp activateIgnoringOtherApps:YES];
[NSApp run];
}
int main (int argc, char const *argv[])
{
OSXInitNSApplication();
OSXCreateMainMenu();
OSXCreateWindow();
// Commenting out this call, allows the program to compile
// and run again.
GameUpdateAndRender();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment