I'm trying to create a static executable which depends on text-icu.
Here is the minified example https://github.com/4e6/text-icu-static-example
To enable static linking, I build icu with --enable-static flag here:
# http://userguide.icu-project.org/packaging#TOC-Link-to-ICU-statically
icu-static = pkgs.icu.overrideAttrs (attrs: {
dontDisableStatic = true;
configureFlags = (attrs.configureFlags or "") + " --enable-static";
outputs = attrs.outputs ++ [ "static" ];
postInstall = ''
mkdir -p $static/lib
mv -v lib/*.a $static/lib
'' + (attrs.postInstall or "");
});
And add following ghc options here:
configureFlags = [
"--ghc-option=-optl=-static"
"--ghc-option=-optl=-pthread"
"--ghc-option=-optl=-L${pkgs.glibc.static}/lib"
"--ghc-option=-optl=-L${pkgs.gmp6.override { withStatic = true; }}/lib"
"--ghc-option=-optl=-L${icu-static.static}/lib"
];
As a result of nix-build ., I'm getting a lot of errors about undefined references, see nix-build.log:
/nix/store/2h1il2pyfh20kc5rh7vnp5a564alxr21-icu4c-59.1-static/lib/libicui18n.a(regexcmp.ao):(.text+0x7805): more undefined references to `icu_59::UVector64::setElementAt(long, int)' follow
/nix/store/2h1il2pyfh20kc5rh7vnp5a564alxr21-icu4c-59.1-static/lib/libicui18n.a(regexcmp.ao): In function `icu_59::RegexCompile::compile(UText*, UParseError&, UErrorCode&)':
(.text+0x8355): undefined reference to `__cxa_throw_bad_array_new_length'
/nix/store/2h1il2pyfh20kc5rh7vnp5a564alxr21-icu4c-59.1-static/lib/libicui18n.a(regexcmp.ao):(.data.rel.ro._ZTIN6icu_5912RegexCompileE[_ZTIN6icu_5912RegexCompileE]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
collect2: error: ld returned 1 exit status
`cc' failed in phase `Linker'. (Exit code: 1)
This setup works with other libraries but fails with text-icu. Any ideas on what I'm doing wrong?
link to github issue
Related
When I try to build very simple a PyO3 module, the compilation stops at the link stage and returns a very long error message. I compile this code on Linux.
The Rust project looks like this:
├ Cargo.toml
└ src/
└ lib.rs
Cargo.toml:
[package]
name = "dytest"
version = "0.1.0"
edition = "2021"
[lib]
name = "dytest"
crate-type = ["cdylib"]
[dependencies]
pyo3 = { version = "0.16", features = ["extension-module"] }
lib.rs:
use pyo3::prelude::*;
#[test]
fn test_print() {
pyo3::prepare_freethreaded_python();
Python::with_gil(|py| py.run( "print('Hello World')", None, None ) );
}
When I now run cargo test, I get a linker error:
error: linking with `cc` failed: exit status: 1
|
= note: "cc" "-m64" [...many, many paths...]
= note: /usr/bin/ld: /home/user/dytest/target/debug/deps/libpyo3-c98e45c2daa36b66.rlib(pyo3-c98e45c2daa36b66.pyo3.b04632a8-cgu.2.rcgu.o): in function `pyo3_ffi::object::Py_DECREF':
/home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/pyo3-ffi-0.16.2/src/object.rs:407: undefined reference to `_Py_Dealloc'
/usr/bin/ld: /home/user/dytest/target/debug/deps/libpyo3-c98e45c2daa36b66.rlib(pyo3-c98e45c2daa36b66.pyo3.b04632a8-cgu.2.rcgu.o): in function `pyo3_ffi::object::Py_None':
/home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/pyo3-ffi-0.16.2/src/object.rs:472: undefined reference to `_Py_NoneStruct'
/usr/bin/ld: /home/user/dytest/target/debug/deps/libpyo3-c98e45c2daa36b66.rlib(pyo3-c98e45c2daa36b66.pyo3.b04632a8-cgu.2.rcgu.o): in function `pyo3::err::PyErr::take':
/home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/pyo3-0.16.2/src/err/mod.rs:264: undefined reference to `PyErr_Fetch'
[...many, many error messages...]
/usr/bin/ld: /home/user/dytest/target/debug/deps/libpyo3-c98e45c2daa36b66.rlib(pyo3-c98e45c2daa36b66.pyo3.b04632a8-cgu.15.rcgu.o): in function `pyo3::types::string::PyString::to_string_lossy':
/home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/pyo3-0.16.2/src/types/string.rs:199: undefined reference to `PyUnicode_AsEncodedString'
collect2: error: ld returned 1 exit status
= help: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
= note: use the `-l` flag to specify native libraries to link
= note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)
error: could not compile `dytest` due to previous error
If I replace
pyo3 = { version = "0.16", features = ["extension-module"] }
with
pyo3 = { version = "0.16" }
everything works, but the PyO3 User Guide explicitly states this feature.
Trying this code on a Windows machine, works.
I assume I am missing some kind of dependency, but I can't figure out, what is missing.
It looks like this is a known PyO3 issue. It is mentioned in their FAQ:
Cargo.toml:
[dependencies.pyo3]
version = "0.16.3"
[features]
extension-module = ["pyo3/extension-module"]
default = ["extension-module"]
cargo test fails with linking errors when the extension-module feature is activated. A workaround is to make the extension-module feature optional and running the tests with
cargo test --no-default-features.
I am using Ubuntu Linux and Android (android-ndk-r21d). When I am compiling my code with ndk-build, I am getting compilation error for posix_spawnp function call. I have included the header <spawn.h> for this function. I am unable to figure what compilation and Link flags I should use for this function in my Android.mk file. Is this function supported on Android-ndk ?
alc#alc:~/src/ForkBench(master)$ ndk-build NDK_PROJECT_PATH=./
[arm64-v8a] Compile : forkBench <= forkBench.c
jni/../forkBench.c:61:12: error: implicit declaration of function 'posix_spawnp' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
status = posix_spawnp(&pid, TRUEAPP, NULL, NULL, launch_argv, NULL);
^
jni/../forkBench.c:90:12: error: implicit declaration of function 'posix_spawnp' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
status = posix_spawnp(&pid, TRUEAPP, NULL, NULL, launch_argv, NULL);
^
2 errors generated.
make: *** [/home/alc/android-ndk-r21d-linux-x86_64/android-ndk-r21d/build/core/build-binary.mk:476: obj/local/arm64-v8a/objs/forkBench/__/forkBench.o] Error 1
I'm opening a dynamic library with a call to dlopen():
void *handle = dlopen("mylib.so", RTLD_LAZY | RTLD_GLOBAL);
if (!handle)
printf("%s", dlerror());
When this is called for a library which has an undefined symbol, the returned handle is NULL and I get the following printed in TTY:
libmylib.so: undefined symbol: < the_symbol_name >
This is fine. But when I call this same code for the same library name for the second time, the returned handle is NOT NULL, and I get a crash when dereferencing it.
From the docs:
If dlopen() fails for any reason, it returns NULL.
So why isn't NULL returned the second time?
I was trying to figure out how to document and alias a param that takes no values with yargs
What I want to do is alias -c to --compile and be able to document --compile. If --compile
script sources -c
I was expecting it to be something like this
var argv = require('yargs')
.usage('Usage: $0 <input> [options]')
.example('$0 src/**.js -c', 'Generate a build')
.demand(1)
.boolean('compile')
.alias('compile', ['c'])
.nargs('c', 1)
.describe('compile', 'Whether to compile the results')
.version(function() {
return require('../package').version;
})
.argv;
However, calling script sources -c will generate an error
TypeError: Cannot read property 'newAliases' of undefined
at Object.self.help (/home/gyeates/code/lodash.modularize/node_modules/yargs/lib/usage.js:135:45)
at Object.self.showHelp (/home/gyeates/code/lodash.modularize/node_modules/yargs/lib/usage.js:211:29)
at Object.Argv.self.showHelp (/home/gyeates/code/lodash.modularize/node_modules/yargs/index.js:303:15)
at Object.self.fail (/home/gyeates/code/lodash.modularize/node_modules/yargs/lib/usage.js:37:39)
Get rid of nargs('c', 1). That method specifies the number of arguments that should be consumed after a key, in this case 1. We don't want the key to take any values.
var argv = require('yargs')
.usage('Usage: $0 <input> [options]')
.example('$0 src/**.js -c', 'Generate a build')
.demand(1)
.boolean('compile')
.alias('compile', ['c'])
.describe('compile', 'Whether to compile the results')
.version(function() {
return require('../package').version;
})
.argv;
More information on yargs methods can be found here.
I know this has been asked a million times, but I can't seem to locate the illegal characters in this line:
window.require.register("templates/application", Function('exports, require, module', "module.exports = Ember.TEMPLATES[module.id.replace('templates\\','')] = Ember.Handlebars.template(function anonymous(Handlebars,depth0,helpers,partials,data) {\nthis.compilerInfo = [2,'>= 1.0.0-rc.3'];\nhelpers = helpers || Ember.Handlebars.helpers; data = data || {};\n var buffer = '', hashTypes, escapeExpression=this.escapeExpression;\n\n\n hashTypes = {};\n data.buffer.push(escapeExpression(helpers._triageMustache.call(depth0, \"outlet\", {hash:{},contexts:[depth0],types:[\"ID\"],hashTypes:hashTypes,data:data})));\n data.buffer.push(\"\\n\");\n return buffer;\n \n});\n//# sourceURL=templates/application.hbs"));
This line is from the app.js file generated using node/brunch from the simple empty branch of https://github.com/cbosco/ember-brunch.
I get the error:
Uncaught SyntaxError: Unexpected token ILLEGAL
in Chrome when pointing to localhost:3333. Firefox gives the following error:
SyntaxError: unterminated string literal
It looks like it's in the generated "templates" code in app.js. The same problem happens in the cbosco todomvc project.
Steps to recreate:
git clone git://github.com/cbosco/ember-brunch.git ember-skeleton -b empty
brunch new my_app -s ./ember-skeleton
cd my_app
brunch watch -s
point browser to localhost:3333