当前位置: 首页 > 工具软件 > Thrifty > 使用案例 >

bison -y -o "src\thrifty.cc" –defines="src/thrifty.hh"

丘浩宕
2023-12-01

问题描述

在使用visual studio 2010 SP1编译thrift-0.9.1的compiler时,出现:

The command "flex -o "src\\thriftl.cc" src/thriftl.ll

bison -y -o "src\thrifty.cc" –defines="src/thrifty.hh" src/thrifty.yy

问题原因

flex和bison原本是linux下的可执行程序,windows上需要分别安装bison.exe和flex.exe。

解决步骤

1)下载并安装bison

此处下载bison安装程序,安装路径随意,比如我安装在D:\dev_tools\GnuWin32目录下,安装之后GnuWin32目录下将包括:

-GnuWin32/

–bin/

–contrib/

–doc/

–include/

–info/

–lib/

–man/

–manifest/

–share/

–uninstall/

2)下载并安装flex

此处下载flex解压包,flex包内包含bin,contrib,man以及manifest四个目录。这里将包内的所有文件夹复制到GnuWin32目录,比如我就复制:

flex/bin -> GnuWin32/

flex/contrib -> GnuWin32/

flex/man ->GnuWin32/

flex/manifest ->GnuWin32/

3)添加环境变量

将GnuWin32/bin(需要全路径)添加到Windows环境变量中。

4)重启Visual Studio 2010 SP1。如果不重启,此时编译依然会报错。

5)此时编译会报错Cannot open source file: ‘src\thriftl.cc’: No such file or directory,原因是compiler工程里边的Pre-Build Event有错。

flex-o "src\\thriftl.cc" src/thriftl.ll
bison -y -o "src\thrifty.cc" –defines="src/thrifty.hh" src/thrifty.yy

flex的语法需要-o之后没有空格,所以需要将-o和src之间的空格去掉,即

flex -o"src\\thriftl.cc" src/thriftl.ll
bison -y -o "src\thrifty.cc" –defines="src/thrifty.hh" src/thrifty.yy

6)接着就是最后一个错误了

Cannot open include file: ‘unistd.h’: No such file or directory

这里会提示找不到unistd.h,unistd.h是linux下的头文件,相当于Windows下的Windows.h。将thriftl.cc中的#include <unistd.h>屏蔽是没有用的,因为这个文件是自动生成的。

在{thrift}/compiler/cpp目录下建立unistd.h空文件,并将compiler工程属性(Properties -> C/C++ -> General -> Additional Include Directories里加入当前目录.即可。

All Done!


原文链接:http://mojijs.com/2014/12/162929/index.html

====================================================================


我自己还遇到了  "不能找到 version.h"的错误,answer:

在项目文件夹-->windows文件夹下新建version.h文件,内容如下:

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

#ifndef _THRIFT_WINDOWS_VERSION_H_
#define _THRIFT_WINDOWS_VERSION_H_ 1

#if defined(_MSC_VER) && (_MSC_VER > 1200)
#pragma once
#endif // _MSC_VER

#ifndef _WIN32
#error "This is a Windows header only"
#endif

#define THRIFT_VERSION "@PACKAGE_VERSION@"

#endif // _THRIFT_WINDOWS_VERSION_H_


然后可能还会遇到:  LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏

answer:   项目——项目属性——配置属性——连接器——清单文件——嵌入清单 “是”改为“否”


 类似资料: