ssalonen / libcec-sys

FFI bindings for the libcec
GNU General Public License v2.0
2 stars 4 forks source link

Windows build with dynamic linking to lib fails #45

Open skraus-dev opened 1 year ago

skraus-dev commented 1 year ago

Bug description

Attempting to build a project which depends on libcec-sys or cec-rs yields error:

LINK : fatal error LNK1181: cannot open input file 'cec.lib'

Smoke tests apparently all fail...

Using 'smoke test' to find out if libcec is installed

Smoke testing with libcec major 6
smoke_abi6.c
build/smoke_abi6.c(6): warning C4013: '_Static_assert' undefined; assuming extern returning int
smoke_abi6.obj : error LNK2019: unresolved external symbol __imp_libcec_initialise referenced in function main
smoke_abi6.obj : error LNK2019: unresolved external symbol _Static_assert referenced in function main
C:\Users\dev\Desktop\cec_example\target\debug\build\libcec-sys-1ce880d6c0beb027\out\smoke_abi6_out.exe : fatal error LNK1120: 2 unresolved externals
smoke_abi6 -> fail: Ok(Output { status: ExitStatus(ExitStatus(2)), stdout: "smoke_abi6.c\r\nbuild/smoke_abi6.c(6): warning C4013: '_Static_assert' undefined; assuming extern returning int\r\nsmoke_abi6.obj : error LNK2019: unresolved external symbol __imp_libcec_initialise
 referenced in function main\r\nsmoke_abi6.obj : error LNK2019: unresolved external symbol _Static_assert referenced in function main\r\nC:\\Users\\dev\\Desktop\\cec_example\\target\\debug\\build\\libcec-sys-1ce880d6c0beb027\\out\\smoke_abi6_out.exe : fatal error LNK1120: 2 unresolved extern
als\r\n", stderr: "" })

Smoke testing with libcec major 5
smoke_abi5.c
build/smoke_abi5.c(6): warning C4013: '_Static_assert' undefined; assuming extern returning int
smoke_abi5.obj : error LNK2019: unresolved external symbol __imp_libcec_initialise referenced in function main
smoke_abi5.obj : error LNK2019: unresolved external symbol _Static_assert referenced in function main
C:\Users\dev\Desktop\cec_example\target\debug\build\libcec-sys-1ce880d6c0beb027\out\smoke_abi5_out.exe : fatal error LNK1120: 2 unresolved externals
smoke_abi5 -> fail: Ok(Output { status: ExitStatus(ExitStatus(2)), stdout: "smoke_abi5.c\r\nbuild/smoke_abi5.c(6): warning C4013: '_Static_assert' undefined; assuming extern returning int\r\nsmoke_abi5.obj : error LNK2019: unresolved external symbol __imp_libcec_initialise
 referenced in function main\r\nsmoke_abi5.obj : error LNK2019: unresolved external symbol _Static_assert referenced in function main\r\nC:\\Users\\dev\\Desktop\\cec_example\\target\\debug\\build\\libcec-sys-1ce880d6c0beb027\\out\\smoke_abi5_out.exe : fatal error LNK1120: 2 unresolved extern
als\r\n", stderr: "" })

Smoke testing with libcec major 4
smoke_abi4.c
build/smoke_abi4.c(6): warning C4013: '_Static_assert' undefined; assuming extern returning int
smoke_abi4.obj : error LNK2019: unresolved external symbol __imp_libcec_initialise referenced in function main
smoke_abi4.obj : error LNK2019: unresolved external symbol _Static_assert referenced in function main
C:\Users\dev\Desktop\cec_example\target\debug\build\libcec-sys-1ce880d6c0beb027\out\smoke_abi4_out.exe : fatal error LNK1120: 2 unresolved externals
smoke_abi4 -> fail: Ok(Output { status: ExitStatus(ExitStatus(2)), stdout: "smoke_abi4.c\r\nbuild/smoke_abi4.c(6): warning C4013: '_Static_assert' undefined; assuming extern returning int\r\nsmoke_abi4.obj : error LNK2019: unresolved external symbol __imp_libcec_initialise
 referenced in function main\r\nsmoke_abi4.obj : error LNK2019: unresolved external symbol _Static_assert referenced in function main\r\nC:\\Users\\dev\\Desktop\\cec_example\\target\\debug\\build\\libcec-sys-1ce880d6c0beb027\\out\\smoke_abi4_out.exe : fatal error LNK1120: 2 unresolved extern
als\r\n", stderr: "" })

Building vendored libcec

Will be happy to send a PR for more detailed README in that regard, if it can be narrowed down.

To Reproduce

Cargo.toml

[package]
name = "cec_example"
version = "0.1.0"
edition = "2021"

[dependencies]
libcec-sys = "4.0.3"

main.rs

use libcec_sys;

fn main() {
    println!("Hello, world!");
}

Expected behavior

Build process of libcec-sys recognizing the cec.dll and dynamically linking with it.

Environment

Additional context

Verbose output for cargo build -vv

       Fresh cc v1.0.82   
       Fresh cmake v0.1.50
       Fresh fs_extra v1.3.0
       Fresh pkg-config v0.3.27
       Dirty libcec-sys v4.0.3: the env variable PATH changed
   Compiling libcec-sys v4.0.3
     Running `C:\Users\dev\Desktop\cec_example\target\debug\build\libcec-sys-c1b139439b26a8d7\build-script-build`
[libcec-sys 4.0.3] cargo:rerun-if-changed=build
[libcec-sys 4.0.3] cargo:rerun-if-changed=vendor
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=LD_LIBRARY_PATH
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=LDFLAGS
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=INCLUDE
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PATH
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_PATH
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=CC
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=CFLAGS
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=CXX
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=CXXFLAGS
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=LIB
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=CL
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=_CL_
[libcec-sys 4.0.3]
[libcec-sys 4.0.3]
[libcec-sys 4.0.3] Using pkg-config to find out if libcec is installed
[libcec-sys 4.0.3]
[libcec-sys 4.0.3]
[libcec-sys 4.0.3] pkg-config with libcec major 6
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=LIBCEC_NO_PKG_CONFIG
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-pc-windows-msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_pc_windows_msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=HOST_PKG_CONFIG
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=LIBCEC_STATIC
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=LIBCEC_DYNAMIC
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-pc-windows-msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_pc_windows_msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_PATH
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-pc-windows-msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_pc_windows_msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-pc-windows-msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_pc_windows_msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=LIBCEC_STATIC
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=LIBCEC_DYNAMIC
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-pc-windows-msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_pc_windows_msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_PATH
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-pc-windows-msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_pc_windows_msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-pc-windows-msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_pc_windows_msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
[libcec-sys 4.0.3] pkg_config(>=6) -> fail: Err(Could not run `"pkg-config" "--libs" "--cflags" "libcec" "libcec >= 6"`
[libcec-sys 4.0.3] The pkg-config command could not be found.
[libcec-sys 4.0.3]
[libcec-sys 4.0.3] Most likely, you need to install a pkg-config package for your OS.
[libcec-sys 4.0.3]
[libcec-sys 4.0.3] If you've already installed it, ensure the pkg-config command is one of the
[libcec-sys 4.0.3] directories in the PATH environment variable.
[libcec-sys 4.0.3]
[libcec-sys 4.0.3] If you did not expect this build to link to a pre-installed system library,
[libcec-sys 4.0.3] then check documentation of the libcec-sys crate for an option to
[libcec-sys 4.0.3] build the library from source, or disable features or dependencies
[libcec-sys 4.0.3] that require pkg-config.)
[libcec-sys 4.0.3]
[libcec-sys 4.0.3]
[libcec-sys 4.0.3] pkg-config with libcec major 5
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=LIBCEC_NO_PKG_CONFIG
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-pc-windows-msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_pc_windows_msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=HOST_PKG_CONFIG
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=LIBCEC_STATIC
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=LIBCEC_DYNAMIC
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-pc-windows-msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_pc_windows_msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_PATH
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-pc-windows-msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_pc_windows_msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-pc-windows-msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_pc_windows_msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=LIBCEC_STATIC
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=LIBCEC_DYNAMIC
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-pc-windows-msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_pc_windows_msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_PATH
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-pc-windows-msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_pc_windows_msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-pc-windows-msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_pc_windows_msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
[libcec-sys 4.0.3] pkg_config(>=5) -> fail: Err(Could not run `"pkg-config" "--libs" "--cflags" "libcec" "libcec >= 5"`
[libcec-sys 4.0.3] The pkg-config command could not be found.
[libcec-sys 4.0.3]
[libcec-sys 4.0.3] Most likely, you need to install a pkg-config package for your OS.
[libcec-sys 4.0.3]
[libcec-sys 4.0.3] If you've already installed it, ensure the pkg-config command is one of the
[libcec-sys 4.0.3] directories in the PATH environment variable.
[libcec-sys 4.0.3]
[libcec-sys 4.0.3] If you did not expect this build to link to a pre-installed system library,
[libcec-sys 4.0.3] then check documentation of the libcec-sys crate for an option to
[libcec-sys 4.0.3] build the library from source, or disable features or dependencies
[libcec-sys 4.0.3] that require pkg-config.)
[libcec-sys 4.0.3]
[libcec-sys 4.0.3]
[libcec-sys 4.0.3] pkg-config with libcec major 4
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=LIBCEC_NO_PKG_CONFIG
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-pc-windows-msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_pc_windows_msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=HOST_PKG_CONFIG
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=LIBCEC_STATIC
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=LIBCEC_DYNAMIC
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-pc-windows-msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_pc_windows_msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_PATH
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-pc-windows-msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_pc_windows_msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-pc-windows-msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_pc_windows_msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=LIBCEC_STATIC
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=LIBCEC_DYNAMIC
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-pc-windows-msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_pc_windows_msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_PATH
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-pc-windows-msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_pc_windows_msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-pc-windows-msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_pc_windows_msvc
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
[libcec-sys 4.0.3] pkg_config(>=4) -> fail: Err(Could not run `"pkg-config" "--libs" "--cflags" "libcec" "libcec >= 4"`
[libcec-sys 4.0.3] The pkg-config command could not be found.
[libcec-sys 4.0.3]
[libcec-sys 4.0.3] Most likely, you need to install a pkg-config package for your OS.
[libcec-sys 4.0.3]
[libcec-sys 4.0.3] If you've already installed it, ensure the pkg-config command is one of the
[libcec-sys 4.0.3] directories in the PATH environment variable.
[libcec-sys 4.0.3]
[libcec-sys 4.0.3] If you did not expect this build to link to a pre-installed system library,
[libcec-sys 4.0.3] then check documentation of the libcec-sys crate for an option to
[libcec-sys 4.0.3] build the library from source, or disable features or dependencies
[libcec-sys 4.0.3] that require pkg-config.)
[libcec-sys 4.0.3] OPT_LEVEL = Some("0")
[libcec-sys 4.0.3] TARGET = Some("x86_64-pc-windows-msvc")
[libcec-sys 4.0.3] HOST = Some("x86_64-pc-windows-msvc")
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=CC_x86_64-pc-windows-msvc
[libcec-sys 4.0.3] CC_x86_64-pc-windows-msvc = None
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=CC_x86_64_pc_windows_msvc
[libcec-sys 4.0.3] CC_x86_64_pc_windows_msvc = None
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=HOST_CC
[libcec-sys 4.0.3] HOST_CC = None
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=CC
[libcec-sys 4.0.3] CC = None
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
[libcec-sys 4.0.3] CRATE_CC_NO_DEFAULTS = None
[libcec-sys 4.0.3] CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
[libcec-sys 4.0.3] DEBUG = Some("true")
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=CFLAGS_x86_64-pc-windows-msvc
[libcec-sys 4.0.3] CFLAGS_x86_64-pc-windows-msvc = None
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=CFLAGS_x86_64_pc_windows_msvc
[libcec-sys 4.0.3] CFLAGS_x86_64_pc_windows_msvc = None
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=HOST_CFLAGS
[libcec-sys 4.0.3] HOST_CFLAGS = None
[libcec-sys 4.0.3] cargo:rerun-if-env-changed=CFLAGS
[libcec-sys 4.0.3] CFLAGS = None
[libcec-sys 4.0.3]
[libcec-sys 4.0.3]
[libcec-sys 4.0.3] Using 'smoke test' to find out if libcec is installed
[libcec-sys 4.0.3]
[libcec-sys 4.0.3]
[libcec-sys 4.0.3] Smoke testing with libcec major 6
[libcec-sys 4.0.3] smoke_abi6.c
[libcec-sys 4.0.3] build/smoke_abi6.c(6): warning C4013: '_Static_assert' undefined; assuming extern returning int
[libcec-sys 4.0.3] smoke_abi6.obj : error LNK2019: unresolved external symbol __imp_libcec_initialise referenced in function main
[libcec-sys 4.0.3] smoke_abi6.obj : error LNK2019: unresolved external symbol _Static_assert referenced in function main
[libcec-sys 4.0.3] C:\Users\dev\Desktop\cec_example\target\debug\build\libcec-sys-1ce880d6c0beb027\out\smoke_abi6_out.exe : fatal error LNK1120: 2 unresolved externals
[libcec-sys 4.0.3] smoke_abi6 -> fail: Ok(Output { status: ExitStatus(ExitStatus(2)), stdout: "smoke_abi6.c\r\nbuild/smoke_abi6.c(6): warning C4013: '_Static_assert' undefined; assuming extern returning int\r\nsmoke_abi6.obj : error LNK2019: unresolved external symbol __imp_libcec_initialise
 referenced in function main\r\nsmoke_abi6.obj : error LNK2019: unresolved external symbol _Static_assert referenced in function main\r\nC:\\Users\\dev\\Desktop\\cec_example\\target\\debug\\build\\libcec-sys-1ce880d6c0beb027\\out\\smoke_abi6_out.exe : fatal error LNK1120: 2 unresolved extern
als\r\n", stderr: "" })
[libcec-sys 4.0.3] 
[libcec-sys 4.0.3] 
[libcec-sys 4.0.3] Smoke testing with libcec major 5
[libcec-sys 4.0.3] smoke_abi5.c
[libcec-sys 4.0.3] build/smoke_abi5.c(6): warning C4013: '_Static_assert' undefined; assuming extern returning int
[libcec-sys 4.0.3] smoke_abi5.obj : error LNK2019: unresolved external symbol __imp_libcec_initialise referenced in function main
[libcec-sys 4.0.3] smoke_abi5.obj : error LNK2019: unresolved external symbol _Static_assert referenced in function main
[libcec-sys 4.0.3] C:\Users\dev\Desktop\cec_example\target\debug\build\libcec-sys-1ce880d6c0beb027\out\smoke_abi5_out.exe : fatal error LNK1120: 2 unresolved externals
[libcec-sys 4.0.3] smoke_abi5 -> fail: Ok(Output { status: ExitStatus(ExitStatus(2)), stdout: "smoke_abi5.c\r\nbuild/smoke_abi5.c(6): warning C4013: '_Static_assert' undefined; assuming extern returning int\r\nsmoke_abi5.obj : error LNK2019: unresolved external symbol __imp_libcec_initialise
 referenced in function main\r\nsmoke_abi5.obj : error LNK2019: unresolved external symbol _Static_assert referenced in function main\r\nC:\\Users\\dev\\Desktop\\cec_example\\target\\debug\\build\\libcec-sys-1ce880d6c0beb027\\out\\smoke_abi5_out.exe : fatal error LNK1120: 2 unresolved extern
als\r\n", stderr: "" })
[libcec-sys 4.0.3]
[libcec-sys 4.0.3]
[libcec-sys 4.0.3] Smoke testing with libcec major 4
[libcec-sys 4.0.3] smoke_abi4.c
[libcec-sys 4.0.3] build/smoke_abi4.c(6): warning C4013: '_Static_assert' undefined; assuming extern returning int
[libcec-sys 4.0.3] smoke_abi4.obj : error LNK2019: unresolved external symbol __imp_libcec_initialise referenced in function main
[libcec-sys 4.0.3] smoke_abi4.obj : error LNK2019: unresolved external symbol _Static_assert referenced in function main
[libcec-sys 4.0.3] C:\Users\dev\Desktop\cec_example\target\debug\build\libcec-sys-1ce880d6c0beb027\out\smoke_abi4_out.exe : fatal error LNK1120: 2 unresolved externals
[libcec-sys 4.0.3] smoke_abi4 -> fail: Ok(Output { status: ExitStatus(ExitStatus(2)), stdout: "smoke_abi4.c\r\nbuild/smoke_abi4.c(6): warning C4013: '_Static_assert' undefined; assuming extern returning int\r\nsmoke_abi4.obj : error LNK2019: unresolved external symbol __imp_libcec_initialise
 referenced in function main\r\nsmoke_abi4.obj : error LNK2019: unresolved external symbol _Static_assert referenced in function main\r\nC:\\Users\\dev\\Desktop\\cec_example\\target\\debug\\build\\libcec-sys-1ce880d6c0beb027\\out\\smoke_abi4_out.exe : fatal error LNK1120: 2 unresolved extern
als\r\n", stderr: "" })
[libcec-sys 4.0.3]
[libcec-sys 4.0.3]
[libcec-sys 4.0.3] Building vendored libcec
[libcec-sys 4.0.3] cargo:lib_vendored=true
[libcec-sys 4.0.3] cargo:libcec_version_major=6
[libcec-sys 4.0.3] cargo:rustc-cfg=abi6
[libcec-sys 4.0.3] Building libcec from local source
[libcec-sys 4.0.3] build libcec
[libcec-sys 4.0.3]  * compiling platform library for amd64
[libcec-sys 4.0.3] The system cannot find the path specified.
[libcec-sys 4.0.3]  --------------------------------------
[libcec-sys 4.0.3]  Generating cmake project:
[libcec-sys 4.0.3]  Architecture = amd64
[libcec-sys 4.0.3]  Project type = "NMake Makefiles"
[libcec-sys 4.0.3]  Cmake ARCH   =
[libcec-sys 4.0.3]  Project      = "C:\Users\dev\Desktop\cec_example\target\debug\build\libcec-sys-1ce880d6c0beb027\out\vendor\src\platform\windows\..\"
[libcec-sys 4.0.3]  Target       = "C:\Users\dev\Desktop\cec_example\target\debug\build\libcec-sys-1ce880d6c0beb027\out\libcec_build\cmake\amd64"
[libcec-sys 4.0.3]  Install      = "C:\Users\dev\Desktop\cec_example\target\debug\build\libcec-sys-1ce880d6c0beb027\out\libcec_build\amd64"
[libcec-sys 4.0.3]  Build type   = Debug
[libcec-sys 4.0.3]  Toolchain    = Visual Studio 16 2019
[libcec-sys 4.0.3]  --------------------------------------
[libcec-sys 4.0.3]
[libcec-sys 4.0.3] CMake Warning (dev) at CMakeLists.txt:1 (project):
[libcec-sys 4.0.3]   cmake_minimum_required() should be called prior to this top-level project()
[libcec-sys 4.0.3]   call.  Please see the cmake-commands(7) manual for usage documentation of
[libcec-sys 4.0.3]   both commands.
[libcec-sys 4.0.3] This warning is for project developers.  Use -Wno-dev to suppress it.
[libcec-sys 4.0.3]
[libcec-sys 4.0.3] CMake Error at CMakeLists.txt:1 (project):
[libcec-sys 4.0.3]   Running
[libcec-sys 4.0.3]
[libcec-sys 4.0.3]    'nmake' '-?'
[libcec-sys 4.0.3]
[libcec-sys 4.0.3]   failed with:
[libcec-sys 4.0.3]
[libcec-sys 4.0.3]    The system cannot find the file specified
[libcec-sys 4.0.3]
[libcec-sys 4.0.3]
[libcec-sys 4.0.3] CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
[libcec-sys 4.0.3] CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
[libcec-sys 4.0.3] -- Configuring incomplete, errors occurred!
[libcec-sys 4.0.3] The system cannot find the path specified.
[libcec-sys 4.0.3]  Compiling "C:\Users\dev\Desktop\cec_example\target\debug\build\libcec-sys-1ce880d6c0beb027\out\libcec_build\cmake\amd64" for amd64 using Visual Studio 16 2019
[libcec-sys 4.0.3] 'nmake' is not recognized as an internal or external command,
[libcec-sys 4.0.3] operable program or batch file.
[libcec-sys 4.0.3] cargo:rustc-link-search=native=C:\Users\dev\Desktop\cec_example\target\debug\build\libcec-sys-1ce880d6c0beb027\out\libcec_build\amd64
[libcec-sys 4.0.3] cargo:rustc-link-lib=cec
     Running `set CARGO=\\?\C:\Users\dev\.rustup\toolchains\stable-x86_64-pc-windows-msvc\bin\cargo.exe&& set CARGO_CRATE_NAME=libcec_sys&& set CARGO_MANIFEST_DIR=C:\Users\dev\.cargo\registry\src\index.crates.io-6f17d22bba15001f\libcec-sys-4.0.3&& set CARGO_PKG_AUTHORS="Sami Salonen"&& set C
ARGO_PKG_DESCRIPTION="FFI bindings to libcec"&& set CARGO_PKG_HOMEPAGE=https://github.com/ssalonen/libcec-sys&& set CARGO_PKG_LICENSE=GPL-2.0&& set CARGO_PKG_LICENSE_FILE=""&& set CARGO_PKG_NAME=libcec-sys&& set CARGO_PKG_README=README.md&& set CARGO_PKG_REPOSITORY=https://github.com/ssalone
n/libcec-sys&& set CARGO_PKG_RUST_VERSION=""&& set CARGO_PKG_VERSION=4.0.3&& set CARGO_PKG_VERSION_MAJOR=4&& set CARGO_PKG_VERSION_MINOR=0&& set CARGO_PKG_VERSION_PATCH=3&& set CARGO_PKG_VERSION_PRE=""&& set OUT_DIR=C:\Users\dev\Desktop\cec_example\target\debug\build\libcec-sys-1ce880d6c0beb
027\out&& set PATH="C:\Users\dev\Desktop\cec_example\target\debug\deps;C:\Users\dev\.rustup\toolchains\stable-x86_64-pc-windows-msvc\bin;C:\Users\dev\.rustup\toolchains\stable-x86_64-pc-windows-msvc\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerS
hell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\;C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Modules\TShell\TShell\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Windows\system32\config\systemprofile\AppData\
Local\Microsoft\WindowsApps;C:\Users\dev\.cargo\bin;C:\Users\dev\AppData\Local\Microsoft\WindowsApps;C:\Users\dev\.dotnet\tools;C:\Program Files (x86)\Pulse-Eight\USB-CEC Adapter\x64"&& rustc --crate-name libcec_sys --edition=2021 C:\Users\dev\.cargo\registry\src\index.crates.io-6f17d22bba15
001f\libcec-sys-4.0.3\src\lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=291 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 --cfg "feature=\"default\"" -C metadata=5bdcb732714be76c -C extra-filename=-
5bdcb732714be76c --out-dir C:\Users\dev\Desktop\cec_example\target\debug\deps -L dependency=C:\Users\dev\Desktop\cec_example\target\debug\deps --cap-lints warn -L native=C:\Users\dev\Desktop\cec_example\target\debug\build\libcec-sys-1ce880d6c0beb027\out\libcec_build\amd64 -l cec --cfg abi6` 
   Compiling cec_example v0.1.0 (C:\Users\dev\Desktop\cec_example)
     Running `set CARGO=\\?\C:\Users\dev\.rustup\toolchains\stable-x86_64-pc-windows-msvc\bin\cargo.exe&& set CARGO_BIN_NAME=cec_example&& set CARGO_CRATE_NAME=cec_example&& set CARGO_MANIFEST_DIR=C:\Users\dev\Desktop\cec_example&& set CARGO_PKG_AUTHORS=""&& set CARGO_PKG_DESCRIPTION=""&& se
t CARGO_PKG_HOMEPAGE=""&& set CARGO_PKG_LICENSE=""&& set CARGO_PKG_LICENSE_FILE=""&& set CARGO_PKG_NAME=cec_example&& set CARGO_PKG_README=""&& set CARGO_PKG_REPOSITORY=""&& set CARGO_PKG_RUST_VERSION=""&& set CARGO_PKG_VERSION=0.1.0&& set CARGO_PKG_VERSION_MAJOR=0&& set CARGO_PKG_VERSION_MI
NOR=1&& set CARGO_PKG_VERSION_PATCH=0&& set CARGO_PKG_VERSION_PRE=""&& set CARGO_PRIMARY_PACKAGE=1&& set PATH="C:\Users\dev\Desktop\cec_example\target\debug\deps;C:\Users\dev\.rustup\toolchains\stable-x86_64-pc-windows-msvc\bin;C:\Users\dev\.rustup\toolchains\stable-x86_64-pc-windows-msvc\bi
n;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\;C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Modules\TShell\TShell\;C:\Program Files (x86)\Wind
ows Kits\8.1\Windows Performance Toolkit\;C:\Windows\system32\config\systemprofile\AppData\Local\Microsoft\WindowsApps;C:\Users\dev\.cargo\bin;C:\Users\dev\AppData\Local\Microsoft\WindowsApps;C:\Users\dev\.dotnet\tools;C:\Program Files (x86)\Pulse-Eight\USB-CEC Adapter\x64"&& rustc --crate-n
ame cec_example --edition=2021 src\main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=291 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=9064c001a4e2d1b3 --out-dir C:\Users\dev\Desktop\cec_example\tar
get\debug\deps -C incremental=C:\Users\dev\Desktop\cec_example\target\debug\incremental -L dependency=C:\Users\dev\Desktop\cec_example\target\debug\deps --extern libcec_sys=C:\Users\dev\Desktop\cec_example\target\debug\deps\liblibcec_sys-5bdcb732714be76c.rlib -L native=C:\Users\dev\Desktop\c
ec_example\target\debug\build\libcec-sys-1ce880d6c0beb027\out\libcec_build\amd64`
warning: unused import: `libcec_sys`
 --> src\main.rs:1:5
  |
1 | use libcec_sys;
  |     ^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

error: linking with `link.exe` failed: exit code: 1181
  |
  = note: "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\bin\\amd64\\link.exe" "/NOLOGO" "C:\\Users\\dev\\AppData\\Local\\Temp\\rustcfNEHsU\\symbols.o" "C:\\Users\\dev\\Desktop\\cec_example\\target\\debug\\deps\\cec_example.132r48g5ng3ivefx.rcgu.o" "C:\\Users\\dev\\Desktop\\cec_
example\\target\\debug\\deps\\cec_example.1em56xmfe62110zg.rcgu.o" "C:\\Users\\dev\\Desktop\\cec_example\\target\\debug\\deps\\cec_example.1zov6zdu19uyd43.rcgu.o" "C:\\Users\\dev\\Desktop\\cec_example\\target\\debug\\deps\\cec_example.1zwx4qnssk56lvvx.rcgu.o" "C:\\Users\\dev\\Desktop\\cec_ex
ample\\target\\debug\\deps\\cec_example.3tjg6i6sg43yc97t.rcgu.o" "C:\\Users\\dev\\Desktop\\cec_example\\target\\debug\\deps\\cec_example.484ho3fye15a81i9.rcgu.o" "C:\\Users\\dev\\Desktop\\cec_example\\target\\debug\\deps\\cec_example.2nvipbqfc6x55fv9.rcgu.o" "/LIBPATH:C:\\Users\\dev\\Desktop
\\cec_example\\target\\debug\\deps" "/LIBPATH:C:\\Users\\dev\\Desktop\\cec_example\\target\\debug\\build\\libcec-sys-1ce880d6c0beb027\\out\\libcec_build\\amd64" "/LIBPATH:C:\\Users\\dev\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Users
\\dev\\Desktop\\cec_example\\target\\debug\\deps\\liblibcec_sys-5bdcb732714be76c.rlib" "C:\\Users\\dev\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-4e8f46f7d0c95848.rlib" "C:\\Users\\dev\\.rustup\\toolchains\\stable-x86_64-pc-windows-
msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-5db344dab6eb1d2b.rlib" "C:\\Users\\dev\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_demangle-74e09b816cbd5555.rlib" "C:\\Users\\dev\\.rustup\\toolchains\\stable-x86_64
-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd_detect-0e78b5195f1cb27a.rlib" "C:\\Users\\dev\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libhashbrown-bfdbaec42e428240.rlib" "C:\\Users\\dev\\.rustup\\toolchains\\stable-x
86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_alloc-ece31b1fa03921a4.rlib" "C:\\Users\\dev\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libminiz_oxide-b1cda3daaedb751f.rlib" "C:\\Users\\dev\\.rustup
\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libadler-fcb0daf3e92ec962.rlib" "C:\\Users\\dev\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-943c8b115715a79a.rlib" "C:\\Users\\dev\\.rustup\\t
oolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcfg_if-86ba8a5505ea3939.rlib" "C:\\Users\\dev\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liblibc-5e13ccbf89e39d2e.rlib" "C:\\Users\\dev\\.rustup\\toolc
hains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-150c9edec7571387.rlib" "C:\\Users\\dev\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_core-cd5722df944967ab.rlib" "C:\\Users\\dev\
\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-f671e54f90f2e08c.rlib" "C:\\Users\\dev\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-0157311a6d6a27aa.rlib" "cec.lib"
 "kernel32.lib" "advapi32.lib" "bcrypt.lib" "kernel32.lib" "ntdll.lib" "userenv.lib" "ws2_32.lib" "kernel32.lib" "msvcrt.lib" "/NXCOMPAT" "/LIBPATH:C:\\Users\\dev\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "/OUT:C:\\Users\\dev\\Desktop\\ce
c_example\\target\\debug\\deps\\cec_example.exe" "/OPT:REF,NOICF" "/DEBUG" "/NATVIS:C:\\Users\\dev\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\intrinsic.natvis" "/NATVIS:C:\\Users\\dev\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\liballo
c.natvis" "/NATVIS:C:\\Users\\dev\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libcore.natvis" "/NATVIS:C:\\Users\\dev\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libstd.natvis"
  = note: LINK : fatal error LNK1181: cannot open input file 'cec.lib'

warning: `cec_example` (bin "cec_example") generated 1 warning
error: could not compile `cec_example` (bin "cec_example") due to previous error; 1 warning emitted
ssalonen commented 1 year ago

Hi! Thanks for the report

I am not sure if we are testing dynamic linking in CI so this might be a new use case.

You can see how build script first attempts to find the dynamic libary by

  1. Pkg config (does not work on your setup)
  2. "Smoke tests" by building small C program to detect the libcec ABI version

Both of the approaches fail and then it reverts to vendored build.

Vendored build fails with link (as you posted). Link is failing because there was no build done. Build was not done because nmake is not found, as far as I can tell:

CMake Error at CMakeLists.txt:1 (project): [libcec-sys 4.0.3] Running [libcec-sys 4.0.3] [libcec-sys 4.0.3] 'nmake' '-?' [libcec-sys 4.0.3] [libcec-sys 4.0.3] failed with: [libcec-sys 4.0.3] [libcec-sys 4.0.3] The system cannot find the file specified

So something is off with visual studio/build setup? The vendored build is tested in CI even.


But to get it to link to the provided shared library/dll, we would like to get the smoke tests working

smoke_abi6.obj : error LNK2019: unresolved external symbol __imp_libcec_initialise referenced in function main
[libcec-sys 4.0.3] smoke_abi6.obj : error LNK2019: unresolved external symbol _Static_assert referenced in function main

This is failure in linking phase so it seems libcec header is found but dll not. Have you found Microsoft documentation on the env variable to set? In linux this is controlled by LD_LIBRARY_PATH.

It also seems that static assertion is not supported by your compiler? We can diagnose this after fixing the libcec linking error -- build script might need some fixing. Found good reference https://learn.microsoft.com/en-us/cpp/c-language/static-assert-c?view=msvc-170

ssalonen commented 1 year ago

Seems like PATH should influence the dll finding process on windows, see https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order

Does that particular error disappear with PATH set to C:\Program Files (x86)\Pulse-Eight\USB-CEC Adapter\x64 ?

ssalonen commented 1 year ago

Pinging @ok-nick from https://github.com/ssalonen/libcec-sys/pull/15 (introduction of windows support)

I noticed the following syntax from Microsoft documentation https://learn.microsoft.com/en-us/cpp/build/reference/compiler-command-line-syntax?view=msvc-170

We are not passing library names to link to now in smoke test build, should we?

https://github.com/ssalonen/libcec-sys/blob/f31b294046f1094adc0c73eab5ffeecb410aed16/build/build.rs#L157

skraus-dev commented 1 year ago

Seems like PATH should influence the dll finding process on windows, see https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order Does that particular error disappear with PATH set to C:\Program Files (x86)\Pulse-Eight\USB-CEC Adapter\x64 ?

Nope, does not solve it unfortunately - it still fails the smoke test. I also attempted to modify the build.rs script and appended /link cec or /link cec.dll - With /link cec.dll it actually complained about not finding cec.dll.

Both of the approaches fail and then it reverts to vendored build.

Correct me if I am wrong, but this feels a bit unintuitive. I understand the idea of best effort when compiling libcec-sys, but it should only do what it's been told - and if not fullfillable - fail hard.

I am continuing research and ultimately targeting to help with simplifying the burden on the user (installing the rather large VS suite.. and a specific build of python etc.) by providing a CI-built repository that includes the different prebuilt flavors of libcec for Windows.

The repository or let's rather say the github workflow is 75% done now finished.

Result: https://github.com/skraus-dev/libcec-vendor

What's missing still is the commit of the binary files back into the repository, so the repo can be easily included as a submodule to consume the bins from there.

PS: If this goes too much off-topic, happy to continue in https://github.com/ssalonen/libcec-sys/issues/24.

PPS: Why use prebuilts? I took the idea from https://github.com/ftdi-rs/libftd2xx-ffi/blob/main/build.rs which just has a quite minimalistic build.rs that does not attempt to build libs and rather just emits compiler directives (except for bindgen). Tbf, libftd2xx does not have the option to compile from source, as the manufacturer FTDI only provides binaries.

ssalonen commented 1 year ago

Quick comments from my phone

Re, vendored feature etc: I have followed the model from some of the major sys crates, should not be too surprising. I see the default feature set as "best effort" not really as "non-vendored"

Re. Prebuilt libraries: I do not completely follow, would not the official libcec distribution included the needed binaries? Or are referring to needed libraries / artifacts for static linking?

ssalonen commented 1 year ago

Re /link, good idea experimenting correct flags. Is it always complaining not finding the right libcec symbol?

Do you agree that we should get that standalone C program build working first? This should be basic C/MSVC stuff, not related to rust at this level. Unfortunately, my understanding is limited

skraus-dev commented 1 year ago

Re. Prebuilt libraries: I do not completely follow, would not the official libcec distribution included the needed binaries? Or are referring to needed libraries / artifacts for static linking?

I am referring to both, dynamic and static linking.

This sums is up: https://learn.microsoft.com/en-us/cpp/build/linking-an-executable-to-a-dll?view=msvc-170

From my understanding, MSCV relies on a *.lib to link against either way, statically or dynamically.

In libcec's case:

You would use the DLL in cases when defining

Bottom-line: Pulse-Eight's Libcec distribution for windows ONLY contains the DLL.

Do you agree that we should get that standalone C program build working first?

Sure!

Is it always complaining not finding the right libcec symbol?

It's solved now:

-> Manual build of libcec via cmdline in Developer Command Prompt worked from this point on.

libcec_sys (vendored) is compiled also successfully, when started from "Developer command prompt".

Next steps

Ensure the theory about *.lib files by experimenting with the linker directives in build.rs

ok-nick commented 1 year ago

Hey, I switched to Linux a while ago so I'm not sure if I could be much help. If you have any other questions I will do my best to answer.

ssalonen commented 1 year ago

@skraus-dev good info, today I learned sometving.

It looks like it might be possible to generate .lib from .dll? https://stackoverflow.com/questions/9946322/how-to-generate-an-import-library-lib-file-from-a-dll

Also, if there's a lot of changes, I propose to rebase on top ci-speedup branch, there are some heavier github CI and build.rs changes. I need to clean up the branch a bit still and merge to main (EDIT: now merged)

Thanks @ok-nick , seems like we figured out the necessary steps

ssalonen commented 1 year ago

Once again regarding preference of vendored vs non-vendored, not sure where I picked that up. Some examples

openssl-sys

I do see similar type of logic is used for static vs dynamic building in openssl-sys: https://github.com/sfackler/rust-openssl/blob/master/openssl-sys/build/main.rs#L351-L398 (if static is explicitly requested, we do static build. Otherwise try to do dynamic build).

However, same crate uses vendored sources only if vendored feature is enabled.

libgit2-sys

https://github.com/rust-lang/git2-rs/blob/master/libgit2-sys/build.rs

Uses vendored when explicitly requested. Vendored can be also disabled with an env variable (LIBGIT2_NO_VENDOR)

    // Specify `LIBGIT2_NO_VENDOR` to force to use system libgit2.
    // Due to the additive nature of Cargo features, if some crate in the
    // dependency graph activates `vendored` feature, there is no way to revert
    // it back. This env var serves as a workaround for this purpose.

Even if user has not explicitly specified the vendored feature, libgit2-sys seems to fall back to vendored build when linking to system lib has failed.

bzip2-rs

https://github.com/alexcrichton/bzip2-rs/blob/master/bzip2-sys/build.rs

With static: always use vendored Without static: prefer system lib, but allow fallback to vendored


So yeah, as summary, practices seem to vary between popular crates...

ssalonen commented 1 year ago

Ideally it would be nice to have the following

Thoughts?

skraus-dev commented 1 year ago
  • find out the visual studio installation and enable it automatically (similar to CI and batch scripts in libcec source) - no need for "developer command prompt"

Yeah that sounds good, to not rely on Developer command prompt environment but rather source the environment ourselves, if found.

this step should then also verify the existance of components cmake (as mentioned in your last bullet-point), nmake and python

  • detect libcec installation in the default folder, and link to it statically by default. Hopefully we could export ".lib" from the ".dll"

While it's possible to forge a *.lib from a DLL, this would still be a dynamic linking - as by default, Pulse-Eight does not deliver the cec-static.lib import library..

Concerning DLL -> Import Library, the new rust 1.71.0 release introduced a nice feature, but that's on you to decide if it's feasible to implement. Allows defining linkage to a DLL inline in code.

PR: https://github.com/rust-lang/rust/pull/109677/

RFC: https://rust-lang.github.io/rfcs/2627-raw-dylib-kind.html

  • provide static feature (windows only), and if enabled, compile the binary against (vendored) libcec statically. I believe currently static build is always part of the vendored build on windows (see Support static linking on Windows #24 (comment) )

Introducing a distinct handling for static linking sounds good!

Static linking the C runtime looks independent from the userspace-library linking.

See: https://doc.rust-lang.org/reference/linkage.html#static-and-dynamic-c-runtimes

  • with vendored build, error out if cmake is missing

See answer to point 1

ssalonen commented 1 year ago

also verify the existance of components cmake (as mentioned in your last bullet-point), nmake and python

👍 minor correction: python should not be needed anymore: https://github.com/ssalonen/libcec-sys/blob/07859ab7676e79fbe196040f950cce54e2945af1/build/build.rs#L109

While it's possible to forge a *.lib from a DLL, this would still be a dynamic linking - as by default, Pulse-Eight does not deliver the cec-static.lib import library..

I see, got it now.

Concerning DLL -> Import Library, the new rust 1.71.0 release introduced a nice feature, but that's on you to decide if it's feasible to implement. Allows defining linkage to a DLL inline in code.

This sounds something worth investigation!

1.71.0 is quite new though...

Static linking the C runtime looks independent from the userspace-library linking.

Yes, "static" feature would only control libcec link, not the C runtime.