How to use CoreFoundation in QuickTime SDK for Windows?

余生长醉 提交于 2019-12-08 09:00:28

问题


Anybody can help me for compile this code in Cygwin / MingW / VS20(05|08|10)?
Indeed i want to use CoreFoundation Framework in QuickTime SDK 7.3 for Windows.

#include <stdio.h>
#include <CoreFoundation.h>

int main () {
    CFStringRef hello = CFSTR("Hello, world.");
    return 0;
}

i used this MakeFile for compile it, in Cygwin/MingW, but i get an error :(

CC = gcc
LDFLAGS = -L"C:/Program Files/QuickTime SDK/Libraries" -lQTMLClient
CFLAGS = -Wall -mwindows -I"C:/Program Files/QuickTime SDK/CIncludes"

all: StringExample.c
$(CC) $(CFLAGS) $(LDFLAGS) -o StringExample StringExample.c -static

Carefree warning message ;)

StringExample.c: In function 'main':
StringExample.c:5:17: warning: unused variable 'hello' [-Wunused-variable]
C:\Users\censored\AppData\Local\Temp\ccJzEryl.o:StringExample.c:(.text+0x16): undefined reference to `_imp____CFStringMakeConstantString'
collect2: ld returned 1 exit status
make: *** [all] Error 1

In VisualStudio 2010, i get the same error:

LNK2019: unresolved external symbol __imp____CFStringMakeConstantString referenced in function _main

i downloaded the Cocotron/CFLite/OpenCFLite but i havent been to compile this Projects or use that :( please help me... im very tried!

Thanks guys for help me.

My english is very bad, i`m so sorry about this.


回答1:


YES!!!
I finally succeeded!
You can add CoreFoundation.dll statically to LDFLAGS MakeFile. (if installed itunes in your system, you can find this file on "program files/common files/apple...")
I've Compiled this code so much easier!

#include <stdio.h>
#include <stdlib.h>
#include <CoreFoundation/CoreFoundation.h>

#define BufferSize 1000

void show(CFStringRef formatString, ...) {
    CFStringRef resultString;
    CFDataRef data;
    va_list argList;

    va_start(argList, formatString);
    resultString = CFStringCreateWithFormatAndArguments(NULL, NULL, formatString, argList);
    va_end(argList);

    data = CFStringCreateExternalRepresentation(NULL, resultString, CFStringGetSystemEncoding(), '?');

    if (data != NULL) {
        printf ("%.*s\n\n", (int)CFDataGetLength(data), CFDataGetBytePtr(data));
        CFRelease(data);
    }

    CFRelease(resultString);
}

int main(){
    CFMutableStringRef mutStr;
    UniChar *myBuffer;

    myBuffer = malloc(BufferSize * sizeof(UniChar));
    mutStr = CFStringCreateMutableWithExternalCharactersNoCopy(NULL, myBuffer, 0, BufferSize, kCFAllocatorNull);
    CFStringAppend(mutStr, CFSTR("eAmin. "));

    show(CFSTR("Hello, %@"), mutStr);

    CFRelease(mutStr);
    free(myBuffer);

   return 0;
}


Edited & none problem makefile:

CC = gcc
LDFLAGS = "CoreFoundation.dll"
CFLAGS = -ICIncludes

all: StringExample.c
$(CC) $(CFLAGS) $(LDFLAGS) -o StringExample StringExample.c -static


Good Luck!



来源:https://stackoverflow.com/questions/6711167/how-to-use-corefoundation-in-quicktime-sdk-for-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!