我在尝试编译我最初没有编写的Objective-c代码时遇到了一些错误。该平台在Windows 10上是GNUstep。我对这一切都很新,所以我怀疑我犯了一个基本错误。
帮助!
编译错误:
$ make
This is gnustep-make 2.6.5. Type 'make print-gnustep-make-help' for help.
Making all for tool stockfish...
Compiling file main.m ...
Compiling file EngineController.mm ...
In file included from EngineController.mm:1:0:
EngineController.h:6:4: error: ISO C++ forbids declaration of 'pthread_cond_t' with no type [-fpermissive]
EngineController.h:6:19: error: expected ';' before 'WaitCondition'
EngineController.h:7:4: error: ISO C++ forbids declaration of 'pthread_mutex_t' with no type [-fpermissive]
EngineController.h:7:20: error: expected ';' before 'WaitConditionLock'
EngineController.mm: In function '-[EngineController initEngine]':
EngineController.mm:10:27: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
EngineController.mm:13:27: error: 'WaitConditionLock' was not declared in this scope
EngineController.mm:13:50: error: 'pthread_mutex_init' was not declared in this scope
EngineController.mm:14:26: error: 'WaitCondition' was not declared in this scope
EngineController.mm:14:45: error: 'pthread_cond_init' was not declared in this scope
EngineController.mm:18:12: warning: 'objc_object* objc_get_class(const char*)' is deprecated (declared at C:/GNUstep/GNUstep/System/Library/Headers/objc/runtime-deprecated.h:30) [-Wdeprecated-declarations]
make[3]: *** [obj/stockfish.obj/EngineController.mm.o] Error 1
make[2]: *** [internal-tool-all_] Error 2
make[1]: *** [stockfish.all.tool.variables] Error 2
make: *** [internal-all] Error 2
GNUmakefile
include $(GNUSTEP_MAKEFILES)/common.make
TOOL_NAME = stockfish
stockfish_OBJC_FILES = main.m
stockfish_OBJCC_FILES = EngineController.mm
include $(GNUSTEP_MAKEFILES)/tool.make
的main.m
#import <Foundation/Foundation.h>
#import <pthread.h>
#import <EngineController.h>
int
main (void)
{
[[Controller alloc] init];
return 0;
}
EngineController.h
#import <Foundation/Foundation.h>
@class Controller;
@interface EngineController : NSObject {
pthread_cond_t WaitCondition;
pthread_mutex_t WaitConditionLock;
BOOL ignoreBestmove;
BOOL engineThreadShouldStop;
BOOL engineThreadIsRunning;
BOOL engineIsThinking;
}
@property (nonatomic, readonly) BOOL engineIsThinking;
@property (nonatomic, readonly) BOOL engineThreadIsRunning;
- (void)initEngine;
@end
extern EngineController *GlobalEngineController;
EngineController.mm
#import "EngineController.h"
EngineController *GlobalEngineController;
@implementation EngineController
@synthesize engineIsThinking, engineThreadIsRunning;
- (void)initEngine {
if (self = [super init]) {
// Initialize locks and conditions
pthread_mutex_init(&WaitConditionLock, NULL);
pthread_cond_init(&WaitCondition, NULL);
// Start engine thread
NSThread *thread =
[[NSThread alloc] initWithTarget: self
selector: @selector(startEngine:)
object: nil];
[thread setStackSize: 0x100000];
[thread start];
[thread release];
ignoreBestmove = NO;
engineIsThinking = NO;
}
GlobalEngineController = self;
}
@end
答案 0 :(得分:0)
discuss-gnustep
邮件列表提供了解决方案:#import <pthread.h>
位于错误的位置。它需要位于EngineController.h
而不是main.m