小编tor*_*gen的帖子

通过LD链接D程序时未定义的符号"开始"

我有以下简单的程序:

import std.stdio;

int main(string[] argv) {
    writeln("Hello, world!");

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我正在构建如下:

DMD -c -m64 -od/proj/out -w -wi -fPIC -debug \
    -g -I/proj/hello -unittest /proj/hello.d

LD -L/usr/share/dmd/lib/ -arch x86_64 -execute -macosx_version_min 10.7 \
    -pie -lm -lpthread -lphobos2 -o /proj/out/hello_app /proj/out/hello.o
Run Code Online (Sandbox Code Playgroud)

编译通过完美,但链接卡与以下:

Undefined symbols for architecture x86_64:
  "start", referenced from:
     -u command line option
     (maybe you meant: _D3std9algorithm41__T10startsWithVAyaa6_61203d3d2062TAhTAhZ10startsWithFAhAhZb, _D4core6thread6Thread5startMFZv , _D3std9algorithm91__T10startsWithVAyaa11_62203c20612e74696d6554TAS3std8datetime13PosixTimeZone10TransitionTlZ10startsWithFAS3std8datetime13PosixTimeZone10TransitionlZb , _D3std9algorithm43__T10startsWithVAyaa6_61203d3d2062TAyaTAyaZ10startsWithFAyaAyaZb , _D3std9algorithm41__T10startsWithVAyaa6_61203d3d2062TAxaTaZ10startsWithFAxaaZb , _D3std9algorithm92__T10startsWithVAyaa11_62203c20612e74696d6554TAS3std8datetime13PosixTimeZone10LeapSecondTylZ10startsWithFAS3std8datetime13PosixTimeZone10LeapSecondylZb , _D3std9algorithm92__T10startsWithVAyaa11_62203c20612e74696d6554TAS3std8datetime13PosixTimeZone10TransitionTylZ10startsWithFAS3std8datetime13PosixTimeZone10TransitionylZb )
ld: symbol(s) not found for architecture x86_64
Run Code Online (Sandbox Code Playgroud)

我想我忘记了一些额外的静态库来链接,让它设置一切,但究竟是什么?

此外,我已经看到有关如何在dlang网站上进行单独编译和链接的说明,但无法找到它.

UPD1: …

linker d ld

7
推荐指数
1
解决办法
2540
查看次数

ES6 Promises和PEP3148期货的链接差异

我对ES6 Promises和PEP3148期货的实施差异进行推理有点困惑.在Javascript中,当Promise与另一个Promise一起解决时,"outer"promise会在解决或拒绝后继承"内部"promise的值.在Python中,"外部"的未来会立即用"内在的"未来来解决,而不是它的最终价值,这就是问题所在.

为了说明这一点,我为两个平台提供了两个代码片段.在Python中,代码如下所示:

import asyncio

async def foo():
    return asyncio.sleep(delay=2, result=42)

async def bar():
    return foo()

async def main():
    print(await bar())

asyncio.get_event_loop().run_until_complete(main())
Run Code Online (Sandbox Code Playgroud)

在Javascript中,完全等效的代码是这样的:

function sleep(delay, result) {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            resolve(result);
        }, delay * 1000);
    });
}

async function foo() {
    return sleep(2, 42);
}

async function bar() {
    return foo();
}

(async function main() {
    console.log(await bar());
})();
Run Code Online (Sandbox Code Playgroud)

sleep 为完整起见而提供的功能.

42正如预期的那样打印Javascript代码.Python代码打印<coroutine object foo at 0x102a05678>和关于"coroutine'foo'的投诉从未等待过".

通过这种方式,JS允许您选择控制将在当前执行上下文中消失的时间点,立即执行awaitpromises,或让调用者等待它们.Python总是让你没有其他选择,而不是总是awaitFuture/coroutine,因为否则你将不得不用一个丑陋的包装器函数在循环中展开Future链,如下所示: …

javascript python future promise async-await

7
推荐指数
1
解决办法
532
查看次数

d2:从C端调用D共享库中的writefln

我正在尝试使用D中的动态共享库快速启动,但我遇到了问题.

我正在构建以下代码dmd -shared ./testlib.d:

module testlib;

import std.c.stdio;

extern (C) export int hello(int a) {
    printf("Number is %d", a);

    return (a + 1);
}
Run Code Online (Sandbox Code Playgroud)

它构建良好,并且有效.但是,当我试图利用以下更多的D'ish来源时:

module testlib;

import std.stdio;

extern (C) export int hello(int a) {
    writefln("Number is %d", a);

    return (a + 1);
}
Run Code Online (Sandbox Code Playgroud)

一旦我试图打电话,它就会失败并出现分段错误hello.我究竟做错了什么?

我正在hello使用Python 调用:

import ctypes

testlib = ctypes.CDLL('testlib.dylib');

print (testlib.hello(10))
Run Code Online (Sandbox Code Playgroud)

UPD1:似乎我也不能使用像Phobos这样的功能std.conv.to!(string).

UPD2: Windows上没有这样的问题,一切似乎都运行正常.Mac OS X受此影响.

UPD3:可能与GC连接.我必须以某种方式初始化GC,但core.memory.GC.enable()仍然失败并出现分段错误.

d shared-libraries

6
推荐指数
1
解决办法
458
查看次数

Windows编程教程中未解析的外部符号__RTC_*

使用Visual Studio Express 2010,我创建了一个Windows项目,其中包含Windows Application和Empty Project选项.然后,我尝试了MSDN Windows教程中的以下代码片段:

#include <windows.h>
#include <shobjidl.h> 

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
{
    HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | 
        COINIT_DISABLE_OLE1DDE);
    if (SUCCEEDED(hr))
    {
        IFileOpenDialog *pFileOpen;

        // Create the FileOpenDialog object.
        hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL, 
                IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen));

        if (SUCCEEDED(hr))
        {
            // Show the Open dialog box.
            hr = pFileOpen->Show(NULL);

            // Get the file name from the dialog box.
            if (SUCCEEDED(hr))
            {
                IShellItem *pItem;
                hr = pFileOpen->GetResult(&pItem);
                if (SUCCEEDED(hr))
                {
                    PWSTR …
Run Code Online (Sandbox Code Playgroud)

c++ windows linker-errors visual-studio-2010

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

C程序中的“数组下标不是整数”

deviation函数向我抛出以下错误:"Array subscript is not an integer". 如果您能帮我找到错误的原因,我将不胜感激。

float average(float data[], int n) {
    float total = 0;
    float *p = data;

    while (p < (data + n)) {
        total = total + *p;
        p++;
    }

    return total / n;
}

float deviation(float data[], int n) {
    float data_average = average(data, n);
    float total;
    float *p = data;

    while (p < (data + n)) {
        total += (data[p] - data_average) * (data[p + 1] - data_average);
    } …
Run Code Online (Sandbox Code Playgroud)

c

6
推荐指数
1
解决办法
8万
查看次数

如何正确使用`__attribute __((format(printf,x,y)))`for C11 U"unicode literals"?

我正在将一个应用程序移植char*到使用UCS4,因为它是内部的Unicode表示.我使用C11 U"unicode literals"来定义字符串,它们扩展为数组char32_t,uint32_t基本上是.

问题在于正确的注释printf函数.作为"格式"不再char*,编译器拒绝进一步编译它,以及它会不会满意char32_t *,而不是char *%s格式,我想.

我根本不依赖于stdlib *printf系列,因此格式化完全由我的实现完成.

什么是正确的解决方案,除了完全禁用此属性?

c unicode gcc c11 unicode-literals

5
推荐指数
1
解决办法
136
查看次数

如何让 ServiceWorker 存活缓存重置/Shift+F5?

我想创建一个即使服务器离线也能工作的网站——我发现这就是ServiceWorkers的用途。

当我使用 service worker 重新加载页面并且没有连接时,它工作得很好。但是,shift+reload(例如绕过缓存)会解除 service worker 的武装,并且出现“无法连接到服务器”错误。

我的问题是——我能否以某种方式防止 shift+reload(shift+f5、ctrl+f5 等)破坏 service worker,或者至少在不恢复连接的情况下使其恢复?

html javascript service-worker

5
推荐指数
1
解决办法
2077
查看次数

`async for` 的语义 - __anext__ 调用可以重叠吗?

如果__anext__将控制权交还给事件循环(通过 anawaitcall_soon/ call_later),是否有可能__anext__在同一实例上调用另一个,而第一个尚未解析,或者它们将排队?是否有任何其他情况下假设只有一个__anext__同时运行是不安全的?

python asynchronous python-3.x python-asyncio

5
推荐指数
1
解决办法
1871
查看次数

在setup.cfg中正确使用PEP 508环境标记

我试图通过指定仅在特定OS上有意义的依赖项来利用PEP 496-环境标记PEP 508-Python软件包的依赖项规范。

我的setup.py样子是这样的:

import setuptools
assert setuptools.__version__ >= '36.0'

setuptools.setup()
Run Code Online (Sandbox Code Playgroud)

我的最小setup.cfg看起来像这样:

[metadata]
name = foobar
version = 1.6.5+0.1.0

[options]
packages = find:

install_requires =
    ham >= 0.1.0
    eggs >= 8.1.2
    spam >= 1.2.3; platform_system=="Darwin"
    i-love-spam >= 1.2.0; platform_system="Darwin"
Run Code Online (Sandbox Code Playgroud)

但是,当尝试使用安装此类软件包时pip install -e foobar/,它将失败并显示:

pip._vendor.pkg_resources.RequirementParseError: Invalid requirement, parse error at "'; platfo'"
Run Code Online (Sandbox Code Playgroud)

我猜这里不希望有分号。但是我应该如何使用环境标记?

python setuptools python-3.x python-packaging

5
推荐指数
1
解决办法
641
查看次数

属性如何像函数一样?

如果您安装颜色,您将看到可以编写如下脚本:

var colors = require('colors');

console.log('hello'.green);
console.log('i like cake and pies'.underline.red)
console.log('inverse the color'.inverse);
console.log('OMG Rainbows!'.rainbow);
console.log('Run the trap'.trap);
Run Code Online (Sandbox Code Playgroud)

属性如何像函数一样(如[5, 6, 4].count?).

我理解'Run the trap'.trap()但不是'Run the trap'.trap

javascript getter properties

4
推荐指数
1
解决办法
34
查看次数