c - 如何在 QuickTime SDK for Windows 中使用 CoreFoundation?

标签 c compilation mingw quicktime core-foundation

有人可以帮我在 Cygwin/MingW/VS20(05|08|10) 中编译这段代码吗?
事实上,我想在 QuickTime SDK 7.3 for Windows 中使用 CoreFoundation Framework。

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

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

我在 Cygwin/MingW 中使用这个 MakeFile 来编译它,但是我得到一个错误:(

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

无忧无虑的警告信息;)

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

在 VisualStudio 2010 中,我得到同样的错误:

LNK2019: unresolved external symbol __imp____CFStringMakeConstantString referenced in function _main

我下载了 Cocotron/CFLite/OpenCFLite 但我还没有 t been to compile this Projects or use that :( please help me... i我很努力!

谢谢大家的帮助。

我的英语很差,对此我感到很抱歉。

最佳答案

是的!!!
我终于成功了!
您可以将 CoreFoundation.dll 静态添加到 LDFLAGS MakeFile。 (如果你的系统中安装了 iTunes,你可以在“program files/common files/apple...”中找到这个文件)
我编译这段代码容易多了!

#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;
}


已编辑且没有问题的 makefile:

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

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


祝你好运!

关于c - 如何在 QuickTime SDK for Windows 中使用 CoreFoundation?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6711167/

相关文章:

c - 分段故障归档 sleep 功能

gcc - 原生树莓派编译问题

c++ - 链接 .lib 文件时出现 VC12 命令行错误

模块内部调用 : resolved by the compiler or linker?

windows - Windows x64 是否有任何 POSIX 兼容层?

c - 未格式化的 C 文件输入/输出

c - 以下与宏相关的代码的输出

c - 如果 C 中的语句没有正确评估?

c++ - ifstream wchar_t minGW C++

C++ 继承 "toString"