Skip to content

build error with Undefined symbols #241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
BruceChar opened this issue Apr 24, 2023 · 3 comments
Closed

build error with Undefined symbols #241

BruceChar opened this issue Apr 24, 2023 · 3 comments

Comments

@BruceChar
Copy link

OS: Macos M2
pcre2: latest as a git submodule
I want to use pcre2 in my rust library as FFI binding.
I build manually as following:

const FILES: &'static [&'static str] = &[
    "pcre2_auto_possess.c",
    "pcre2_compile.c",
    "pcre2_config.c",
    "pcre2_context.c",
    "pcre2_convert.c",
    "pcre2_dfa_match.c",
    "pcre2_error.c",
    "pcre2_extuni.c",
    "pcre2_find_bracket.c",
    "pcre2_jit_compile.c",
    "pcre2_maketables.c",
    "pcre2_match.c",
    "pcre2_match_data.c",
    "pcre2_newline.c",
    "pcre2_ord2utf.c",
    "pcre2_pattern_info.c",
    "pcre2_script_run.c",
    "pcre2_serialize.c",
    "pcre2_string_utils.c",
    "pcre2_study.c",
    "pcre2_substitute.c",
    "pcre2_substring.c",
    "pcre2_tables.c",
    "pcre2_ucd.c",
    "pcre2_valid_utf.c",
    "pcre2_xclass.c",
];

fn main() {
    println!("cargo:rerun-if-env-changed=PCRE2_SYS_STATIC");

    println!("cargo:rustc-link-search=pcre2-sys/target/");

    let target = env::var("TARGET").unwrap();
    let out = PathBuf::from("./target");

    // make sure our pcre2 submodule has been loaded.
    if has_git() && !Path::new("pcre2/.git").exists() {
        Command::new("git")
            .args(&["submodule", "update", "--init"])
            .status()
            .unwrap();
    }

    let mut builder = cc::Build::new();
    builder
        .out_dir("./target")
        .define("PCRE2_CODE_UNIT_WIDTH", "8")
        .define("HAVE_STDLIB_H", "1")
        .define("HAVE_MEMMOVE", "1")
        .define("HEAP_LIMIT", "20000000")
        .define("LINK_SIZE", "2")
        .define("MATCH_LIMIT", "10000000")
        .define("MATCH_LIMIT_DEPTH", "10000000")
        .define("MAX_NAME_COUNT", "10000")
        .define("MAX_NAME_SIZE", "32")
        .define("NEWLINE_DEFAULT", "2")
        .define("PARENS_NEST_LIMIT", "250")
        .define("PCRE2_STATIC", "1")
        .define("STDC_HEADERS", "1")
        .define("SUPPORT_PCRE2_8", "1")
        .define("SUPPORT_UNICODE", "1")
        .define("PCRE2GREP_BUFSIZE", "20480")
        .define("PCRE2GREP_MAX_BUFSIZE", "1048576");

    if target.contains("windows") {
        builder.define("HAVE_WINDOWS_H", "1");
    }

    let include = out.join("include");
    fs::create_dir_all(&include).unwrap();
    fs::copy("pcre2/src/config.h.generic", include.join("config.h")).unwrap();
    fs::copy("pcre2/src/pcre2.h.generic", include.join("pcre2.h")).unwrap();

    let src = out.join("src");
    fs::create_dir_all(&src).unwrap();
    fs::copy(
        "pcre2/src/pcre2_chartables.c.dist",
        src.join("pcre2_chartables.c"),
    ).unwrap();

    builder
        .include("pcre2/src")
        .include(&include)
        .file(src.join("pcre2_chartables.c"));
    for file in FILES {
        builder.file(Path::new("pcre2/src").join(file));
    }

    if env::var("PCRE2_SYS_DEBUG").unwrap_or(String::new()) == "1" {
        builder.debug(true);
    }
    builder.compile("pcre2");
}

It does generate the libpcre2.a in my target dir, but with following error message:

= note: Undefined symbols for architecture arm64:
            "__pcre2_ckd_smul", referenced from:
                _compile_branch in libpcre2_sys-d9ee7d271cdd3ff9.rlib(pcre2_compile.o)
          ld: symbol(s) not found for architecture arm64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)
          

error: could not compile `xipin-resolution` due to previous error

Caused by:
  process didn't exit successfully: `CARGO=/Users/bruce/.rustup/toolchains/stable-aarch64-apple-darwin/bin/cargo CARGO_BIN_NAME=xipin-resolution CARGO_CRATE_NAME=xipin_resolution CARGO_MANIFEST_DIR=/Users/bruce/rust/xipin-resolution CARGO_PKG_AUTHORS='' CARGO_PKG_DESCRIPTION='' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=xipin-resolution CARGO_PKG_REPOSITORY='' CARGO_PKG_RUST_VERSION='' CARGO_PKG_VERSION=0.1.0 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=1 CARGO_PKG_VERSION_PATCH=0 CARGO_PKG_VERSION_PRE='' CARGO_PRIMARY_PACKAGE=1 DYLD_FALLBACK_LIBRARY_PATH='/Users/bruce/rust/xipin-resolution/target/debug/deps:/Users/bruce/.rustup/toolchains/stable-aarch64-apple-darwin/lib:/Users/bruce/.rustup/toolchains/stable-aarch64-apple-darwin/lib:/Users/bruce/lib:/usr/local/lib:/usr/lib' rustc --crate-name xipin_resolution --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=103 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C metadata=db95aced289ff1f5 -C extra-filename=-db95aced289ff1f5 --out-dir /Users/bruce/rust/xipin-resolution/target/debug/deps -C incremental=/Users/bruce/rust/xipin-resolution/target/debug/incremental -L dependency=/Users/bruce/rust/xipin-resolution/target/debug/deps --extern libc=/Users/bruce/rust/xipin-resolution/target/debug/deps/liblibc-8088543c15d6a2dc.rlib --extern pcre2_sys=/Users/bruce/rust/xipin-resolution/target/debug/deps/libpcre2_sys-d9ee7d271cdd3ff9.rlib -L pcre2-sys/target/ -L native=./target` (exit status: 1)

Did missing something?

@PhilipHazel
Copy link
Collaborator

You didn't miss something; I did. I recently noticed that the file pcre2_chkdint.c was missing from the source files listed in NON-AUTOTOOLS-BUILD. I think that is the cause of your problem. (It is a fairly recent addition to the source.)

@BruceChar
Copy link
Author

BruceChar commented Apr 24, 2023

Yup! It does work with pcre2_chkint.c. But strange that I once built successfully with the same version a few days ago. But it fails these days and never be success any more.

@PhilipHazel
Copy link
Collaborator

You must be building from the Git repository source, because that file was only introduced recently, and is not in the 10.42 release. So perhaps you previously copied the source before that file was created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants