标签: porting

在Xcode中编译C++类:编译期间出错:stl vector

我有一个C++类,可以在linux上使用gcc和visual studio中的寡妇进行编译.

boid.h:

#ifndef BOID_CLASS_HEADER_DEFINES_H
#define BOID_CLASS_HEADER_DEFINES_H
#include "defines.h"

class Boid {

public:
     // Initialize the boid with random position, heading direction and color
     Boid(float SceneRadius,float NormalVel);

     .....
protected:
     ...
};

#endif
Run Code Online (Sandbox Code Playgroud)

并在boid.cpp中:

#include "Boid.h"

// Initialize the boid with random position, heading direction and color
Boid::Boid(float SceneRadius,float NormalVel) 
{
    ....
}
Run Code Online (Sandbox Code Playgroud)

但是,当我在Xcode中编译此代码时,我收到以下错误:

Compiling Boid.h: "error: vector: No such file or directory"
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?我以为你可以使用C/C++代码并在Xcode中编译它而没有问题?

谢谢

编辑:添加了define.h(还将#endif添加到示例中,但是在原始代码中)

编辑2:在评论出几个包括空的时间后,我得到了一个不同的错误:上面的向量错误.

#ifndef BOID_NAV_DEFINES_H
#define BOID_NAV_DEFINES_H
#include <stdlib.h>
#include <vector>
#include "Vector3d.h"
#include "Point3d.h" …
Run Code Online (Sandbox Code Playgroud)

c++ xcode porting

10
推荐指数
2
解决办法
3万
查看次数

如何将此NetHack函数移植到Python?

我正在尝试编写一个Python函数,它返回与游戏NetHack中相同的月相值.这可以在hacklib.c中找到.

我试图简单地从NetHack代码中复制相应的函数,但我不相信我得到了正确的结果.

我写的功能是phase_of_the_moon().

功能position()phase(),我在网上找到,我用它们作为我的功能成功的指示.它们非常准确,结果与nethack.alt.org服务器大致相符(请参阅http://alt.org/nethack/moon/pom.txt).然而,我所追求的是原始NetHack函数的精确复制,特性完整无缺.

我希望我的功能和'控制'功能至少给出相同的月相,但目前他们没有,我不知道为什么!

这是NetHack代码:

/*
 * moon period = 29.53058 days ~= 30, year = 365.2422 days
 * days moon phase advances on first day of year compared to preceding year
 *  = 365.2422 - 12*29.53058 ~= 11
 * years in Metonic cycle (time until same phases fall on the same days of
 *  the month) = 18.6 ~= 19
 * moon phase on first day of year …
Run Code Online (Sandbox Code Playgroud)

c python time porting nethack

10
推荐指数
1
解决办法
1413
查看次数

为什么我在Python中收到错误消息'无法导入名称NoneType'?

我正在尝试将一些代码从2转换为3以及以下简单的脚本

import types
from types import NoneType
Run Code Online (Sandbox Code Playgroud)

结果是

ImportError:无法导入名称NoneType

如何将上述内容从2转换为3?

python porting python-3.x

10
推荐指数
1
解决办法
5059
查看次数

使用基本C++获取系统滴答计数?

我本质上想要重建getTickCount()窗口函数,这样我就可以在基本的C++中使用它而不需要任何非标准库甚至STL.(因此它符合随Android NDK提供的库)

我看过了

时钟()

当地时间

时间

但我仍然不确定是否可以使用时间库复制getTickCount窗口函数.

任何人都可以指出我正确的方向,如何做到这一点,甚至可能吗?

我想要做的概述:

我希望能够计算应用程序"执行"某个功能的时间.

因此,例如,我希望能够计算应用程序尝试向服务器注册的时间

我试图从Windows移植它在基于Linux的Android上运行,这里是windows代码:


int TimeoutTimer::GetSpentTime() const
{
if (m_On)
{
    if (m_Freq>1)
    {
        unsigned int now;
        QueryPerformanceCounter((int*)&now);
        return (int)((1000*(now-m_Start))/m_Freq);
    }
    else
    {
        return (GetTickCount()-(int)m_Start);
    }
}
return -1;
}
Run Code Online (Sandbox Code Playgroud)

c++ time porting android-ndk

9
推荐指数
2
解决办法
3万
查看次数

在移植c代码时,win32对alarm,bzero,bcopy的替代方法是什么?

我使用visual studio express将c代码移植到Windows 32位
我现在有3个功能,我在Windows中找不到任何替代方案
:
alarm
bzero
bcopy
C win32中的等效方法是什么?

c winapi porting

9
推荐指数
2
解决办法
2万
查看次数

ANTLR4语法中的集合当前不支持规则引用

我正在尝试将Chris Lambro的ANTLR3Javascript语法移植到ANTLR4

我收到以下错误,

集合中当前不支持规则引用"LT"

在以下代码中 ~(LT)*

LineComment
    : '//'  ~(LT)* -> skip
    ;

LT  : '\n'      // Line feed.
    | '\r'      // Carriage return.
    | '\u2028'  // Line separator.
    | '\u2029'  // Paragraph separator.
    ;
Run Code Online (Sandbox Code Playgroud)

我需要帮助理解为什么我会收到此错误,以及如何解决它.

porting antlr3 antlr4

9
推荐指数
1
解决办法
2688
查看次数

如何在OS X上取消设置env变量?

我正在研究一个makefile规则,并希望在递归调用make之前取消设置环境变量MAKEFILES.在其他BSD系统上,我这样做:

env -u MAKEFLAGS $(MAKE) $(SUBDIR_ARGS)
Run Code Online (Sandbox Code Playgroud)

在Linux上,我这样做:

env --unset=MAKEFLAGS $(MAKE) $(SUBDIR_ARGS)
Run Code Online (Sandbox Code Playgroud)

但是,这两种风格都不适用于Macintosh OS X Mavericks,不过,我希望其他地方使用的BSD风格也可以.

我通过BSD样式调用得到的错误是:

env: illegal option -- u
Run Code Online (Sandbox Code Playgroud)

如何在OS X上调用命令之前取消设置环境变量,为什么其他地方使用的BSD样式不起作用?

这是Mac的env手册页:

ENV(1)                    BSD General Commands Manual                   ENV(1)

NAME
     env -- set and print environment

SYNOPSIS
     env [-i] [name=value ...] [utility [argument ...]]

DESCRIPTION
     env executes utility after modifying the environment as specified on the command line.  The option name=value specifies an environmental variable, name, with a value of value.  The option `-i' causes env to completely ignore …
Run Code Online (Sandbox Code Playgroud)

macos porting environment-variables

9
推荐指数
1
解决办法
6779
查看次数

如何在OS X上从std :: basic_ios获取文件描述符for clang?

我将一些代码移植到Darwin OS X,作为更改的一部分,我们从gcc转到clang编译器.

在代码中,有一个功能可追溯到2005年,并在互联网上发布了几个地方.它为几个不同的旧版GCC提供了功能,我已经删除了它提供的最后一个版本,v3.4.0或更高版本.代码取决于两个GCC特定类:__gnu_cxx::stdio_filebuf__gnu_cxx::stdio_sync_filebuf.

//! Similar to fileno(3), but taking a C++ stream as argument instead of a
//! FILE*.  Note that there is no way for the library to track what you do with
//! the descriptor, so be careful.
//! \return  The integer file descriptor associated with the stream, or -1 if
//!   that stream is invalid.  In the latter case, for the sake of keeping the
//!   code as similar to fileno(3), errno …
Run Code Online (Sandbox Code Playgroud)

c++ macos porting iostream file-descriptor

9
推荐指数
1
解决办法
1028
查看次数

什么是摆脱"警告C4267可能丢失数据"的最佳策略?

我将一些遗留代码从win32移植到win64.不是因为Win32对象的大小是为我们的需求太少,而是因为Win64的是现在比较标准,我们希望端口的所有我们的环境,以这种格式(和我们也使用一些第三方库提供的64位比32位更好的性能) .

我们最终得到了大量的;

警告C4267:'参数':从'size_t'转换为'...',可能会丢失数据

主要是由于代码如下:unsigned int size = v.size();哪里v是STL容器.

我知道为什么警告有意义,我知道它为什么发布以及如何解决.但是,在这个具体的例子中,我们从未经历过容器大小unsigned int过去超过最大值的情况....所以当代码移植到64位环境时,没有理由出现这个问题.

我们讨论了什么是最好的策略来压制那些嘈杂的警告(他们可能会隐藏我们将会遗漏的相关警告),但我们无法对适当的策略做出决定.

所以我在这里问这个问题,最佳推荐策略是什么?

1.使用 static_cast

用一个static_cast.做unsigned int size = static_cast<unsigned int>(v.size());.我并不"喜欢",因为我们放弃了64位容量来在容器中存储大量数据.但由于我们的代码从未达到32位限制,所以这似乎是一个安全的解决方案......

2.替换unsigned intsize_t

这肯定更难,因为unsigned int size上面示例中的对象可以被设置为其他函数,保存为类属性,然后删除单行警告可能最终导致数百个代码更改...

3.禁用警告

这很可能是一个非常糟糕的主意,因为在这种情况下uint8_t size = v.size()它也会禁用警告,这肯定会导致数据丢失....

4.定义"安全演员"*功能并使用它

像这样的东西:

template <typename From, typename To> To safe_cast( const From& value )
{
    //assert( value < std::numeric_limits<To>::max() && value > std::numeric_limits<To>::min() );
    // Edit 19/05: test above fails in some …
Run Code Online (Sandbox Code Playgroud)

c++ windows porting casting suppress-warnings

9
推荐指数
1
解决办法
2867
查看次数

将 jsx 转换为 tsx?

我有一个定义了 proptypes 的 React 组件库,我正在考虑切换到 Typescript。是否有任何工具可以帮助移植代码?这是一个简单组件的示例道具集:

  static propTypes = {
    active: PropTypes.bool,
    children: PropTypes.node,
    disabled: PropTypes.bool,
    icon: Icon.propTypes.kind,
    tabIndex: PropTypes.number
  };
Run Code Online (Sandbox Code Playgroud)

我正在想象一个工具可以将其转换为以下内容:

  static propTypes = {
    active: PropTypes.bool,
    children: PropTypes.node,
    disabled: PropTypes.bool,
    icon: Icon.propTypes.kind,
    tabIndex: PropTypes.number
  };
Run Code Online (Sandbox Code Playgroud)

写起来并不难,但如果它已经存在就好了。

javascript porting transformation typescript reactjs

9
推荐指数
2
解决办法
2万
查看次数