PHP:不能成功执行protoc
我克隆了Protobuf-PHP存储库:https://github.com/drslump/Protobuf-PHP.git,我在https://github.com/drslump/Protobuf-PHP找到了,我一直在进行安装和配置尝试获取protoc-gen-php将原始文件转换为PHP类大约12小时的问题。
我正在运行PHP 5.3.2版,这是我所做的:
我有一个原始文件,我们正在根目录文件夹中使用C#项目,在那里检出了proto-gen-php项目(见下文)。
message AuditLogEntry {
required int64 ID = 1;
required int64 Date = 2;
required string Message = 3;
optional int32 User_ID = 4;
optional string User_Username = 5;
optional int32 ImpUser_ID = 6;
optional string ImpUser_Username = 7;
optional string RemoteIP = 8;
}
message AuditLogQuery {
optional int64 DateRangeStart = 1;
optional int64 DateRangeEnd = 2;
optional string Search = 3;
optional int32 UserID = 4;
optional int32 Limit = 5;
optional int32 Offset = 6;
}
message AuditLogResult {
repeated AuditLogEntry LogEntries = 1;
optional int32 TotalResults = 2;
}
以下是我遇到的几个问题:
当我尝试执行最基本的实现时:
protoc-gen-php.bat AuditLog.proto
我得到这个错误:
无法打开输入文件:@ bin_dir @ protoc-gen-php文件名,目录名称或卷标语法不正确。
我无法在线找到有关此错误的任何信息。 安装我正在使用的其中一个软件包是否存在配置问题? 有任何想法吗?
由于上述错误,我在protoc-gen-php批处理文件中更改了这一行:
"%PHPBIN%" -d display_errors=stderr -d log_errors=On -d error_log=Off "@bin_dir@protoc-gen-php" %*
至
"%PHPBIN%" -d display_errors=stderr -d log_errors=On -d error_log=Off "protoc-gen-php.php" %*
现在,当我运行问题1中给出的相同命令时,我得到以下输出:
The filename, directory name, or volume label syntax is incorrect.
Protobuf-PHP @package_version@ by Ivan -DrSlump- Montes
C:DevelopmentSkedFlexphp-proto-buffersAuditLog.proto: File does not reside within any path specified using --proto_path (or -I). You must specify a --proto_path which encompasses this file. Note that the proto_path must be an exact prefix of the .proto file names -- protoc is too dumb to figure out when two paths (e.g. absolute and relative) are equivalent (it's harder than you think).
ERROR: protoc exited with an error (1) when executed with:
protoc
--plugin=protoc-gen-php="C:DevelopmentSkedFlexphp-proto-buffersprotoc-gen-php.php.bat"
--proto_path="C:DevelopmentSkedFlexphp-proto-bufferslibraryDrSlumpProtobufCompilerprotos"
--php_out=":./"
"C:DevelopmentSkedFlexphp-proto-buffersAuditLog.proto"
我尝试了许多使用-i,-o命令的变体,如手册中所述:http://drslump.github.com/Protobuf-PHP/protoc-gen-php.1.html,但似乎无法取得进展这个...
最后我试图直接执行protoc:
protoc --plugin=protoc-gen-php --php_out=./build AuditLog.proto
这是错误:
--php_out: protoc-gen-php: The system cannot find the file specified.
我正处于被卡住的地步。 有没有人有protoc-gen-php的经验,可以帮助我解决我遇到的问题?
.bat文件在从资源库检出后不能直接使用,创建Pear软件包时会对其进行修改。 因此,您应该使用Pear安装Protobuf-PHP,除非您想以某种方式修改库的源代码。
pear channel-discover pear.pollinimini.net
pear install drslump/Protobuf-beta
如果你不想从梨安装,你将不得不手动修改protoc-gen-php.bat
文件,用类似这样的代替最后一行:
C:pathtophp.exe -d display_errors=stderr -d log_errors=On -d error_log=Off c:pathtoprotobuf-phpprotoc-gen-php %*
为了解决“文件不驻留在指定的任何路径...”错误,您必须确保任何作为参数给出的原始文件驻留在定义的包含路径中。 Google的protoc
编译器不会去猜测包含路径是什么,所以我们需要在所有情况下手动提供它们。
protoc-gen-php.bat -i . AuditLog.proto
这应该允许你为你的proto消息生成PHP文件,尽管这个脚本在Windows系统中不像在Linux和OSX中那样经过测试。 如果您发现任何问题,可以根据需要直接在项目现场报告。
链接地址: http://www.djcxy.com/p/11117.html