Thanks!
**It compiles when only adding this crate `pgx` as a dependency and not using 
it to write some functions.**(In other words no functions use this dependency).
When using it to write some Enclave functions,**the enclave part of my project 
finishes compiling,but fails to link**:
```zsh
    Finished dev [unoptimized + debuginfo] target(s) in 1m 23s
/usr/bin/ld: 
./lib/libenclave.a(pgx_pg_sys-fc533ebe75dea904.pgx_pg_sys.646afbca-cgu.9.rcgu.o):
 in function `pgx_pg_sys::submodules::panic::do_ereport':
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/panic.rs:368:
 undefined reference to `ErrorContext'
/usr/bin/ld: 
./lib/libenclave.a(pgx_pg_sys-fc533ebe75dea904.pgx_pg_sys.646afbca-cgu.9.rcgu.o):
 in function `pgx_pg_sys::all_versions::MemoryContextSwitchTo':
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/lib.rs:513:
 undefined reference to `CurrentMemoryContext'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/lib.rs:515:
 undefined reference to `CurrentMemoryContext'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/lib.rs:513:
 undefined reference to `CurrentMemoryContext'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/lib.rs:515:
 undefined reference to `CurrentMemoryContext'
/usr/bin/ld: ./lib/libenclave.a(pgx-cshim.o): in function `list_nth_cell':
/home/xin201501/.pgx/15.1/pgx-install/include/postgresql/server/nodes/pg_list.h:258:
 undefined reference to `ExceptionalCondition'
/usr/bin/ld: ./lib/libenclave.a(pgx-cshim.o): in function `list_nth':
/home/xin201501/.pgx/15.1/pgx-install/include/postgresql/server/nodes/pg_list.h:280:
 undefined reference to `ExceptionalCondition'
/usr/bin/ld: ./lib/libenclave.a(pgx-cshim.o): in function 
`GetMemoryChunkContext':
/home/xin201501/.pgx/15.1/pgx-install/include/postgresql/server/utils/memutils.h:131:
 undefined reference to `ExceptionalCondition'
/usr/bin/ld: 
/home/xin201501/.pgx/15.1/pgx-install/include/postgresql/server/utils/memutils.h:124:
 undefined reference to `ExceptionalCondition'
/usr/bin/ld: 
/home/xin201501/.pgx/15.1/pgx-install/include/postgresql/server/utils/memutils.h:123:
 undefined reference to `ExceptionalCondition'
/usr/bin/ld: ./lib/libenclave.a(pgx-cshim.o): in function `pgx_elog':
/home/xin201501/incubator-teaclave-sgx-sdk/samplecode/template/enclave/target/x86_64-unknown-linux-sgx/debug/build/pgx-pg-sys-451c5dc41c4634b5/out/cshim/pgx-cshim.c:38:
 undefined reference to `errstart'
/usr/bin/ld: 
/home/xin201501/incubator-teaclave-sgx-sdk/samplecode/template/enclave/target/x86_64-unknown-linux-sgx/debug/build/pgx-pg-sys-451c5dc41c4634b5/out/cshim/pgx-cshim.c:38:
 undefined reference to `errmsg_internal'
/usr/bin/ld: ./lib/libenclave.a(pgx-cshim.o): in function `pgx_ereport':
/home/xin201501/incubator-teaclave-sgx-sdk/samplecode/template/enclave/target/x86_64-unknown-linux-sgx/debug/build/pgx-pg-sys-451c5dc41c4634b5/out/cshim/pgx-cshim.c:98:
 undefined reference to `errstart'
/usr/bin/ld: 
/home/xin201501/incubator-teaclave-sgx-sdk/samplecode/template/enclave/target/x86_64-unknown-linux-sgx/debug/build/pgx-pg-sys-451c5dc41c4634b5/out/cshim/pgx-cshim.c:99:
 undefined reference to `errcode'
/usr/bin/ld: 
/home/xin201501/incubator-teaclave-sgx-sdk/samplecode/template/enclave/target/x86_64-unknown-linux-sgx/debug/build/pgx-pg-sys-451c5dc41c4634b5/out/cshim/pgx-cshim.c:100:
 undefined reference to `errmsg'
/usr/bin/ld: 
/home/xin201501/incubator-teaclave-sgx-sdk/samplecode/template/enclave/target/x86_64-unknown-linux-sgx/debug/build/pgx-pg-sys-451c5dc41c4634b5/out/cshim/pgx-cshim.c:102:
 undefined reference to `errdetail'
/usr/bin/ld: 
/home/xin201501/incubator-teaclave-sgx-sdk/samplecode/template/enclave/target/x86_64-unknown-linux-sgx/debug/build/pgx-pg-sys-451c5dc41c4634b5/out/cshim/pgx-cshim.c:105:
 undefined reference to `errcontext_msg'
/usr/bin/ld: ./lib/libenclave.a(pgx-cshim.o): in function `fastgetattr':
/home/xin201501/.pgx/15.1/pgx-install/include/postgresql/server/access/htup_details.h:761:
 undefined reference to `ExceptionalCondition'
/usr/bin/ld: ./lib/libenclave.a(pgx-cshim.o): in function `list_nth_cell':
/home/xin201501/.pgx/15.1/pgx-install/include/postgresql/server/nodes/pg_list.h:259:
 undefined reference to `ExceptionalCondition'
/usr/bin/ld: 
/home/xin201501/.pgx/15.1/pgx-install/include/postgresql/server/nodes/pg_list.h:259:
 undefined reference to `ExceptionalCondition'
/usr/bin/ld: 
/home/xin201501/.pgx/15.1/pgx-install/include/postgresql/server/nodes/pg_list.h:259:
 undefined reference to `ExceptionalCondition'
/usr/bin/ld: ./lib/libenclave.a(pgx-cshim.o): in function `list_nth_int':
/home/xin201501/.pgx/15.1/pgx-install/include/postgresql/server/nodes/pg_list.h:291:
 undefined reference to `ExceptionalCondition'
/usr/bin/ld: 
./lib/libenclave.a(pgx-cshim.o):/home/xin201501/.pgx/15.1/pgx-install/include/postgresql/server/nodes/pg_list.h:259:
 more undefined references to `ExceptionalCondition' follow
/usr/bin/ld: ./lib/libenclave.a(pgx-cshim.o): in function `pgx_elog':
/home/xin201501/incubator-teaclave-sgx-sdk/samplecode/template/enclave/target/x86_64-unknown-linux-sgx/debug/build/pgx-pg-sys-451c5dc41c4634b5/out/cshim/pgx-cshim.c:38:
 undefined reference to `errfinish'
/usr/bin/ld: ./lib/libenclave.a(pgx-cshim.o): in function `pgx_errcontext_msg':
/home/xin201501/incubator-teaclave-sgx-sdk/samplecode/template/enclave/target/x86_64-unknown-linux-sgx/debug/build/pgx-pg-sys-451c5dc41c4634b5/out/cshim/pgx-cshim.c:48:
 undefined reference to `errcontext_msg'
/usr/bin/ld: ./lib/libenclave.a(pgx-cshim.o): in function `pgx_ereport':
/home/xin201501/incubator-teaclave-sgx-sdk/samplecode/template/enclave/target/x86_64-unknown-linux-sgx/debug/build/pgx-pg-sys-451c5dc41c4634b5/out/cshim/pgx-cshim.c:107:
 undefined reference to `errfinish'
/usr/bin/ld: ./lib/libenclave.a(pgx-cshim.o): in function `heap_getattr':
/home/xin201501/.pgx/15.1/pgx-install/include/postgresql/server/access/htup_details.h:798:
 undefined reference to `getmissingattr'
/usr/bin/ld: ./lib/libenclave.a(pgx-cshim.o): in function `fastgetattr':
/home/xin201501/.pgx/15.1/pgx-install/include/postgresql/server/access/htup_details.h:764:
 undefined reference to `nocachegetattr'
/usr/bin/ld: ./lib/libenclave.a(pgx-cshim.o): in function `heap_getattr':
/home/xin201501/.pgx/15.1/pgx-install/include/postgresql/server/access/htup_details.h:803:
 undefined reference to `heap_getsysattr'
/usr/bin/ld: ./lib/libenclave.a(pgx-cshim.o): in function `pgx_ARR_NELEMS':
/home/xin201501/incubator-teaclave-sgx-sdk/samplecode/template/enclave/target/x86_64-unknown-linux-sgx/debug/build/pgx-pg-sys-451c5dc41c4634b5/out/cshim/pgx-cshim.c:201:
 undefined reference to `ArrayGetNItems'
/usr/bin/ld: ./lib/libenclave.a(pgx-cshim.o): in function `pgx_SpinLockAcquire':
/home/xin201501/incubator-teaclave-sgx-sdk/samplecode/template/enclave/target/x86_64-unknown-linux-sgx/debug/build/pgx-pg-sys-451c5dc41c4634b5/out/cshim/pgx-cshim.c:231:
 undefined reference to `s_lock'
/usr/bin/ld: 
./lib/libenclave.a(pgx_pg_sys-fc533ebe75dea904.pgx_pg_sys.646afbca-cgu.15.rcgu.o):
 in function `pgx_pg_sys::submodules::thread_check::init_active_thread':
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/thread_check.rs:41:
 undefined reference to `pthread_atfork'
/usr/bin/ld: 
./lib/libenclave.a(pgx_pg_sys-fc533ebe75dea904.pgx_pg_sys.646afbca-cgu.3.rcgu.o):
 in function `pgx_pg_sys::submodules::ffi::pg_guard_ffi_boundary_impl':
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:72:
 undefined reference to `CurrentMemoryContext'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:73:
 undefined reference to `PG_exception_stack'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:74:
 undefined reference to `error_context_stack'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:76:
 undefined reference to `__sigsetjmp'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:80:
 undefined reference to `PG_exception_stack'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:100:
 undefined reference to `CurrentMemoryContext'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:129:
 undefined reference to `PG_exception_stack'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:130:
 undefined reference to `error_context_stack'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:86:
 undefined reference to `PG_exception_stack'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:87:
 undefined reference to `error_context_stack'
/usr/bin/ld: 
./lib/libenclave.a(pgx_pg_sys-fc533ebe75dea904.pgx_pg_sys.646afbca-cgu.3.rcgu.o):
 in function `pgx_pg_sys::pg15::CopyErrorData::{{closure}}':
/home/xin201501/incubator-teaclave-sgx-sdk/samplecode/template/enclave/target/x86_64-unknown-linux-sgx/debug/build/pgx-pg-sys-451c5dc41c4634b5/out/pg15.rs:13399:
 undefined reference to `CopyErrorData'
/usr/bin/ld: 
./lib/libenclave.a(pgx_pg_sys-fc533ebe75dea904.pgx_pg_sys.646afbca-cgu.3.rcgu.o):
 in function `pgx_pg_sys::submodules::ffi::pg_guard_ffi_boundary_impl':
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:72:
 undefined reference to `CurrentMemoryContext'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:73:
 undefined reference to `PG_exception_stack'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:74:
 undefined reference to `error_context_stack'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:76:
 undefined reference to `__sigsetjmp'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:80:
 undefined reference to `PG_exception_stack'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:100:
 undefined reference to `CurrentMemoryContext'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:129:
 undefined reference to `PG_exception_stack'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:130:
 undefined reference to `error_context_stack'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:86:
 undefined reference to `PG_exception_stack'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:87:
 undefined reference to `error_context_stack'
/usr/bin/ld: 
./lib/libenclave.a(pgx_pg_sys-fc533ebe75dea904.pgx_pg_sys.646afbca-cgu.3.rcgu.o):
 in function `pgx_pg_sys::pg15::FreeErrorData::{{closure}}':
/home/xin201501/incubator-teaclave-sgx-sdk/samplecode/template/enclave/target/x86_64-unknown-linux-sgx/debug/build/pgx-pg-sys-451c5dc41c4634b5/out/pg15.rs:13408:
 undefined reference to `FreeErrorData'
/usr/bin/ld: 
./lib/libenclave.a(pgx_pg_sys-fc533ebe75dea904.pgx_pg_sys.646afbca-cgu.3.rcgu.o):
 in function `pgx_pg_sys::submodules::ffi::pg_guard_ffi_boundary_impl':
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:72:
 undefined reference to `CurrentMemoryContext'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:73:
 undefined reference to `PG_exception_stack'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:74:
 undefined reference to `error_context_stack'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:76:
 undefined reference to `__sigsetjmp'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:80:
 undefined reference to `PG_exception_stack'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:100:
 undefined reference to `CurrentMemoryContext'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:129:
 undefined reference to `PG_exception_stack'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:130:
 undefined reference to `error_context_stack'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:86:
 undefined reference to `PG_exception_stack'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:87:
 undefined reference to `error_context_stack'
/usr/bin/ld: 
./lib/libenclave.a(pgx_pg_sys-fc533ebe75dea904.pgx_pg_sys.646afbca-cgu.3.rcgu.o):
 in function `pgx_pg_sys::pg15::palloc0::{{closure}}':
/home/xin201501/incubator-teaclave-sgx-sdk/samplecode/template/enclave/target/x86_64-unknown-linux-sgx/debug/build/pgx-pg-sys-451c5dc41c4634b5/out/pg15.rs:13716:
 undefined reference to `palloc0'
/usr/bin/ld: 
./lib/libenclave.a(pgx_pg_sys-fc533ebe75dea904.pgx_pg_sys.646afbca-cgu.3.rcgu.o):
 in function `pgx_pg_sys::submodules::ffi::pg_guard_ffi_boundary_impl':
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:72:
 undefined reference to `CurrentMemoryContext'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:73:
 undefined reference to `PG_exception_stack'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:74:
 undefined reference to `error_context_stack'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:76:
 undefined reference to `__sigsetjmp'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:80:
 undefined reference to `PG_exception_stack'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:100:
 undefined reference to `CurrentMemoryContext'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:129:
 undefined reference to `PG_exception_stack'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:130:
 undefined reference to `error_context_stack'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:86:
 undefined reference to `PG_exception_stack'
/usr/bin/ld: 
/home/xin201501/.cargo/registry/src/github.com-1ecc6299db9ec823/pgx-pg-sys-0.6.1/src/submodules/ffi.rs:87:
 undefined reference to `error_context_stack'
/usr/bin/ld: 
./lib/libenclave.a(pgx_pg_sys-fc533ebe75dea904.pgx_pg_sys.646afbca-cgu.3.rcgu.o):
 in function `pgx_pg_sys::pg15::pfree::{{closure}}':
/home/xin201501/incubator-teaclave-sgx-sdk/samplecode/template/enclave/target/x86_64-unknown-linux-sgx/debug/build/pgx-pg-sys-451c5dc41c4634b5/out/pg15.rs:13755:
 undefined reference to `pfree'
collect2: error: ld returned 1 exit status
make: *** [Makefile:160:bin/enclave.so] 错误 1
```
---
Many `undefined references` are used by `pg_sys` crate,an underlying crate 
which has many `FFI Calls` to communicate with underlying database.
I found that this `pg_sys` crate uses its own `CFLAGS` to compile some C 
code.Perhaps they are not compatible with enclave environment.
These C functions are indeed hard to deal with.We almost have no control of 
them...

-- 
Reply to this email directly or view it on GitHub:
https://github.com/apache/incubator-teaclave-sgx-sdk/issues/415#issuecomment-1374742943
You are receiving this because you are subscribed to this thread.

Message ID: <apache/incubator-teaclave-sgx-sdk/issues/415/1374742...@github.com>

Reply via email to