meson linker error when adding dependency - c++

I am trying to switch to meson and evaluate. I setup a small project and created this meson.build file
project('utils', 'cpp')
json_dep = dependency('jsoncpp')
boost_dep = dependency('boost', modules : [ 'filesystem' ])
occ_dep = dependency('OpenCASCADE', method: 'cmake')
utils_deps = [ occ_dep, json_dep, boost_dep ]
utils_lib = library('utils', dependencies: utils_deps)
If I use utils_deps = [ json_dep, boost_dep ] then the compilation works. However adding occ_dep to the list and compiling produces the following error
FAILED: src/libs/utils/libutils.dylib
c++ -o src/libs/utils/libutils.dylib -Wl,-dead_strip_dylibs -Wl,
-headerpad_max_install_names -Wl,-undefined,error -shared -install_name
#rpath/libutils.dylib -Wl,-rpath,/opt/homebrew/Cellar/jsoncpp/1.9.5/lib
/opt/homebrew/lib/libTKernel.7.6.2.dylib /opt/homebrew/opt/tbb/lib/libtbb.dylib
/opt/homebrew/opt/tbb/lib/libtbbmalloc.dylib /opt/homebrew/lib/libTKMath.7.6.2.dylib
/opt/homebrew/lib/libTKG2d.7.6.2.dylib /opt/homebrew/lib/libTKG3d.7.6.2.dylib
/Library/Developer/CommandLineTools/SDKs/
MacOSX12.sdk/System/Library/Frameworks/AppKit.framework
/Library/Developer/CommandLineTools/SDKs/
MacOSX12.sdk/System/Library/Frameworks/IOKit.framework
/opt/homebrew/lib/libTKService.7.6.2.dylib
/opt/homebrew/opt/freeimage/lib/libfreeimage.dylib
/opt/homebrew/opt/freetype/lib/libfreetype.dylib
/Library/Developer/CommandLineTools/SDKs/
MacOSX12.sdk/System/Library/Frameworks/AppKit.framework
/opt/homebrew/lib/libTKQADraw.7.6.2.dylib
/opt/homebrew/Cellar/jsoncpp/1.9.5/lib/libjsoncpp.dylib
/opt/homebrew/Cellar/boost/1.78.0_1/lib/libboost_filesystem-mt.dylib
ld: can't map file, errno=22 file '/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/System/Library/Frameworks/AppKit.framework' for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
I am working on a Macbook Pro M1 cheap.
Thanks

it seems that in the linking file it search a file instead of Library
/Developer/CommandLineTools/SDKs/MacOSX12.sdk/System/Library/Frameworks/AppKit.framework
your dependency against OpenCascade uses cmake method, try to specify also the lib needed using modules method
occ_dep = dependency('OpenCASCADE', method: 'cmake', modules : ['openCascade lib ......'])
see also https://mesonbuild.com/Dependencies.html

Related

How can I compile a C++ library statically with Bazel to use in Rust?

My goal is to get a .a static library on linux from the MediaPipe project, which is built with Bazel. To my knowledge, there is no bazel rule for doing so. I really don't want to integrate with Bazel - I want it to produce what I need, and use it in other non-Bazel-managed things.
I'm trying to integrate MediaPipe (https://github.com/google/mediapipe) which uses the google build system Bazel, with a personal project written in Rust. I'm trying to figure out how to get a static library (.a) out of the bazel build system. I've searched around and found people saying they've tried it and done it, but nobody has posted what they've done.
My attempt thus far has been to make bazel verbose (run with -s) and then see what commands it passes to compiling the final binary so I could take it and modify it to build a static library. I've tried parsing the compiler command args to pick out all the object files (.o) and link them with ar like so ar rcs gpu.a $(grep -E '\.o' bazel-bin/custom/run_gpu-2.params)
That command works, but when I try to link it to Rust with rust fails.
Here's my build.rs
fn main() {
println!("cargo:rustc-link-search=/home/me/dev/mediapipe");
}
And here's my main
#[link(name = "gpu")]
extern "C" {
fn square(val: i32) -> i32;
}
fn main() {
let r = unsafe { square(3) };
println!("3 squared is {}", r);
}
And here's the error I get:
Compiling my-mediapipe-project v0.1.0 (/home/me/dev/my-mediapipe-project)
error: linking with `cc` failed: exit code: 1
|
= note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/me/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/home/me/dev/my-mediapipe-project/target/debug/deps/rust_whiteboard-a37e83e58c99436c.1fmokwdndpsbxaxm.rcgu.o" "/home/me/dev/my-mediapipe-project/target/debug/deps/rust_whiteboard-a37e83e58c99436c.2j9fb5mr4wpkcnpp.rcgu.o" "/home/me/dev/my-mediapipe-project/target/debug/deps/rust_whiteboard-a37e83e58c99436c.3bpsevdikgyu7tj9.rcgu.o" "/home/me/dev/my-mediapipe-project/target/debug/deps/rust_whiteboard-a37e83e58c99436c.48fsbok7dmpjlo4o.rcgu.o" "/home/me/dev/my-mediapipe-project/target/debug/deps/rust_whiteboard-a37e83e58c99436c.4ezfxccf1xedvrna.rcgu.o" "/home/me/dev/my-mediapipe-project/target/debug/deps/rust_whiteboard-a37e83e58c99436c.577bi7s5mtonhdwp.rcgu.o" "/home/me/dev/my-mediapipe-project/target/debug/deps/rust_whiteboard-a37e83e58c99436c.qpj0hauia5ocv8m.rcgu.o" "-o" "/home/me/dev/my-mediapipe-project/target/debug/deps/rust_whiteboard-a37e83e58c99436c" "/home/me/dev/my-mediapipe-project/target/debug/deps/rust_whiteboard-a37e83e58c99436c.22pad9p4rf6ea56q.rcgu.o" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs" "-L" "/home/me/dev/my-mediapipe-project/target/debug/deps" "-L" "/home/me/dev/mediapipe" "-L" "/home/me/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-lgpu" "-Wl,--start-group" "-Wl,-Bstatic" "/home/me/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-c32b051c3aafd36c.rlib" "/home/me/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-eabf8b29c0a244dd.rlib" "/home/me/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-5c336cc1b5ec2048.rlib" "/home/me/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-c7631f762b1ba6d9.rlib" "/home/me/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libbacktrace-db0f6c539591c951.rlib" "/home/me/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libbacktrace_sys-32c2dc6fbc292c9c.rlib" "/home/me/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-84e9c510dc249620.rlib" "/home/me/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-13bc027534de0b4c.rlib" "/home/me/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-b3c13ecda1794c6c.rlib" "/home/me/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-72dc11de859645e9.rlib" "/home/me/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-a78b04f112feb31a.rlib" "/home/me/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-29469f6c53ac35f8.rlib" "/home/me/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-0eb3c513c640c4a6.rlib" "-Wl,--end-group" "/home/me/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-0b278345638bce90.rlib" "-Wl,-Bdynamic" "-ldl" "-lrt" "-lpthread" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lutil" "-lutil"
= note: /usr/bin/ld: cannot find -lgpu
collect2: error: ld returned 1 exit status
Here it is manually line-wrapped:
error: linking with `cc` failed: exit code: 1
|
= note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/me/.rustup/toolchains
/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/home/me/dev/my-
mediapipe-project/target/debug/deps/rust_whiteboard-a37e83e58c99436c.1fmokwdndpsbxaxm.rcgu.o"
"/home/me/dev/my-mediapipe-project/target/debug/deps/rust_whiteboard-
a37e83e58c99436c.2j9fb5mr4wpkcnpp.rcgu.o" "/home/me/dev/my-mediapipe-project/target/debug
/deps/rust_whiteboard-a37e83e58c99436c.3bpsevdikgyu7tj9.rcgu.o" "/home/me/dev/my-mediapipe-
project/target/debug/deps/rust_whiteboard-a37e83e58c99436c.48fsbok7dmpjlo4o.rcgu.o" "/home
/me/dev/my-mediapipe-project/target/debug/deps/rust_whiteboard-
a37e83e58c99436c.4ezfxccf1xedvrna.rcgu.o" "/home/me/dev/my-mediapipe-project/target/debug
/deps/rust_whiteboard-a37e83e58c99436c.577bi7s5mtonhdwp.rcgu.o" "/home/me/dev/my-mediapipe-
project/target/debug/deps/rust_whiteboard-a37e83e58c99436c.qpj0hauia5ocv8m.rcgu.o" "-o" "/home
/me/dev/my-mediapipe-project/target/debug/deps/rust_whiteboard-a37e83e58c99436c" "/home/me/dev
/my-mediapipe-project/target/debug/deps/rust_whiteboard-
a37e83e58c99436c.22pad9p4rf6ea56q.rcgu.o" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow"
"-nodefaultlibs" "-L" "/home/me/dev/my-mediapipe-project/target/debug/deps" "-L" "/home/me/dev
/mediapipe" "-L" "/home/me/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib
/x86_64-unknown-linux-gnu/lib" "-lgpu" "-Wl,--start-group" "-Wl,-Bstatic" "/home/me/.rustup
/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-
c32b051c3aafd36c.rlib" "/home/me/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib
/x86_64-unknown-linux-gnu/lib/libpanic_unwind-eabf8b29c0a244dd.rlib" "/home/me/.rustup
/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib
/libhashbrown-5c336cc1b5ec2048.rlib" "/home/me/.rustup/toolchains/stable-x86_64-unknown-linux-
gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-
c7631f762b1ba6d9.rlib" "/home/me/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib
/x86_64-unknown-linux-gnu/lib/libbacktrace-db0f6c539591c951.rlib" "/home/me/.rustup/toolchains
/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libbacktrace_sys-
32c2dc6fbc292c9c.rlib" "/home/me/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib
/x86_64-unknown-linux-gnu/lib/librustc_demangle-84e9c510dc249620.rlib" "/home/me/.rustup
/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-
13bc027534de0b4c.rlib" "/home/me/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib
/x86_64-unknown-linux-gnu/lib/libcfg_if-b3c13ecda1794c6c.rlib" "/home/me/.rustup/toolchains
/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-
72dc11de859645e9.rlib" "/home/me/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib
/x86_64-unknown-linux-gnu/lib/liballoc-a78b04f112feb31a.rlib" "/home/me/.rustup/toolchains
/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib
/librustc_std_workspace_core-29469f6c53ac35f8.rlib" "/home/me/.rustup/toolchains/stable-x86_64-
unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-0eb3c513c640c4a6.rlib"
"-Wl,--end-group" "/home/me/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib
/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-0b278345638bce90.rlib" "-Wl,-Bdynamic"
"-ldl" "-lrt" "-lpthread" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lutil" "-lutil"
= note: /usr/bin/ld: cannot find -lgpu
collect2: error: ld returned 1 exit status
I'm on Arch Linux if it helps. MediaPipe does compile correctly for me - I had to modify a few definitions relating to OpenCV to get it to work properly, I found that documented in a GitHub issue.
I really don't want to have to manage my Rust code through Bazel. I'd really like to just be able to produce a static binary, and then consume it through Rust/Cargo.
I'd really love it if there was a cross platform solution for this too...
When you build a cc_library in Bazel it will compile a both a target_name.{a|so}, with other shared lib extensions on windows/mac, though that doesn't seem to be important in this case. e.g. running;
$ bazel build //mediapipe/gpu:gpu_service
INFO: Analyzed target //mediapipe/gpu:gpu_service (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //mediapipe/gpu:gpu_service up-to-date:
bazel-bin/mediapipe/gpu/libgpu_service.a
bazel-bin/mediapipe/gpu/libgpu_service.so
INFO: Elapsed time: 0.102s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
NOTE: Tested on GitHub codespaces default environment i.e. Ubuntu Linux.
Note here that the path to the library that you built is printed to stdout. i.e. bazel-bin/mediapipe/gpu/libgpu_service.a. You can copy this anywhere you need to integrate that into your cargo build.

Library not found for -ljson11 but -lsqlite 3 is found

I'm trying to implement this tutorial with the addition that I want to include the json11 C++ library.
I followed the same process for both, downloaded the repo from:
https://github.com/libmx3/mx3, added them to the /deps/ folder of my project, and ran GYP to generate the .xcodeproj files for both.
Then I create a C++ project, add both the projects into the workspace, and add the libraries under Build Phases->Link binaries with libraries.
When I hit run the build fails with ld: library not found for -ljson11
I have tried regenerating them and adding them into the main xcodeproj. and into the Target Dependencies.
I have double-checked the library projects and they are identical. I have also added the folders where the .a files are compiled in Library Search paths but none of this makes a difference. If I remove the json11 dependency the project compiles, but I can't understand why the sqlite3 is found and throws no errors but the identical json11 project won't work.
I can see the .a files in the Debug-build folder and there are no errors if I build them separately.
Heres the full build log
Ld /Users/myuser/Library/Developer/Xcode/DerivedData/DjinniTest-eqaqzcfyskdxupbqpdngkdmoidtq/Build/Products/Debug/DjinniTest normal x86_64
cd /Users/myuser/Documents/Dev/djinni_test/cpp_project
export MACOSX_DEPLOYMENT_TARGET=10.11
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++
-arch x86_64
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk
-L/Users/myuser/Library/Developer/Xcode/DerivedData/DjinniTest-eqaqzcfyskdxupbqpdngkdmoidtq/Build/Products/Debug
-L/Users/myuser/Library/Developer/Xcode/DerivedData/DjinniTest-eqaqzcfyskdxupbqpdngkdmoidtq/Build/Products/Debug/..
-F/Users/myuser/Library/Developer/Xcode/DerivedData/DjinniTest-eqaqzcfyskdxupbqpdngkdmoidtq/Build/Products/Debug
-filelist /Users/myuser/Library/Developer/Xcode/DerivedData/DjinniTest-eqaqzcfyskdxupbqpdngkdmoidtq/Build/Intermediates/DjinniTest.build/Debug/DjinniTest.build/Objects-normal/x86_64/DjinniTest.LinkFileList
-mmacosx-version-min=10.11
-stdlib=libc++
-ljson11
-lsqlite3
-Xlinker
-dependency_info
-Xlinker /Users/myuser/Library/Developer/Xcode/DerivedData/DjinniTest-eqaqzcfyskdxupbqpdngkdmoidtq/Build/Intermediates/DjinniTest.build/Debug/DjinniTest.build/Objects-normal/x86_64/DjinniTest_dependency_info.dat
-o /Users/myuser/Library/Developer/Xcode/DerivedData/DjinniTest-eqaqzcfyskdxupbqpdngkdmoidtq/Build/Products/Debug/DjinniTest
ld: library not found for
-ljson11
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Edit: even if I add the compiled files into the project so that they turn black, it still complains that the ljson11 library is not found. Maybe there's something wrong with the way the library is compiled?
Both the libraries gave warning that "macosx" was not found in the supported platforms. When I added it into the json11 project settings, the build compiled and both the warnings disappeared.
SQlite3 still only has iOS(iphone,iphonesimulator) but it compiles fine. I wonder what the difference is.

Add C++ Library to eclipse C++ Project

I am attempting to add an existing library to Eclipse. I use a cross compiler for C++ with the Eclipse IDE, installed on a virtual linux debian machine.
The mmapGpio lib is found here.
/mmapGpioBasicRev1.tar.gz has a cpp and an h file with a small demo program.
I have compiled this code without a problem. A .o file is generated. I've archived the file successfully with ar -q libmmapGpio.a mmapgpio.o
I've placed my libmmapGpio.a in ~/.../UserLib directory
I've placed my mmapGpio.h in ~/.../UserInclude
At this point all is OK.
I open a new project that uses the mmapGpio library:
#include "mmapGpio.h"
#include "stdio.h"
int main(void){
mmapGpio rpiGpio; // instantiate an instance of the mmapGpio class
rpiGpio.setPinDir(17,mmapGpio::OUTPUT); // set GPIO17 to output
while(1) {// toggle pin as fast as possible
rpiGpio.writePinHigh(17);
rpiGpio.writePinLow(17);
}
return 0;
}
So cross-compilation is done, but linker say cannot find -llibmapGpio!
I have made declaration in the properties project; C/C++ General
includes path : /home/octopuss/rpi/UserInclude (the mmapGpio.h file)
Library path : /home/octopuss/rpi/UserLib (the libmmapGpio.a file)
Libraries : libmmapGpio
Why do I receive this message?
for detail -> console view
03:16:30 **** Build of configuration Debug for project Gpio1 ****
make all
Building file: ../Gpio1.cpp
Invoking: Cross G++ Compiler
arm-linux-gnueabihf-g++ -I/home/octopuss/rpi/UserInclude -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"Gpio1.d" -MT"Gpio1.d" -o "Gpio1.o" "../Gpio1.cpp"
Finished building: ../Gpio1.cpp
Building target: Gpio1
Invoking: Cross G++ Linker
arm-linux-gnueabihf-g++ -L/home/octopuss/rpi/UserLib -o "Gpio1" ./Gpio1.o -lmmapGpio
/home/octopuss/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: skipping incompatible /home/octopuss/rpi/UserLib/libmmapGpio.so when searching for -lmmapGpio
/home/octopuss/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lmmapGpio
collect2: error: ld returned 1 exit status
make: *** [Gpio1] Erreur 1
error :
skipping incompatible /home/.../UserLib/libmmapGpio.so when searching for -lmmapGpio
ld: cannot find -lmmapGpio
"why this message ?"
It's because with your settings, the linker actually looks up for a library file named liblibmmapGpio.a.
"... so crosscompilation is done but linker say "cannot find -llibmapGpio" !
...
- Libraries : libmmapGpio"
You just need to specify the library without the lib prefix in the linker library settings:
mmapGpio
The Eclipse CDT Builder passes this as a -l option to the linker, which automatically extends to search for libmmapGpio.a at the specified additional pathes.
See also this Q&A for more illustrated samples and links:
Problems importing libraries to my c++ project, how to fix this?
I found the problem ... my .so lib wasn't ARM cross compiled so there is a X86 library not compatible whith my ARM Programm.
I solve this to set erm-linuxgnuabihf- prefix and his path to cross setting parameter.
Thanks to TTAVAR PEI and Scott Stensland
enjoy

Eclipse: Edit toolchain (remove build step to create a shared library for CUDA)

I am trying to configure Eclipse such that it compiles a shared library in one project and uses it in another.
The problem is, that using the CUDA plugin for Eclipse one can only choose an executable generating project type.
So what I want to do is creating such a project and modify that toolchain such that Eclipse does not execute anything else than nvcc.
As you can see compiling the library is not a problem:
18:27:25 **** Incremental Build of configuration Default for project cudamath ****
make all
Building file: ../test.cu
Invoking: CUDA NVCC Compiler
nvcc --shared -Xcompiler -fPIC -o "cu_test.o" "../test.cu" && \
echo -n 'cu_test.d' ./ > 'cu_test.d' && \
nvcc -M "../test.cu" >> 'cu_test.d'
nvcc warning : The 'compute_10' and 'sm_10' architectures are deprecated, and may be removed in a future release.
nvcc warning : The 'compute_10' and 'sm_10' architectures are deprecated, and may be removed in a future release.
Finished building: ../test.cu
The problem is that Eclipse then calls g++ which is that step of the toolchain I want to cut off:
Building target: cudamath
Invoking: C++ Linker
g++ -L/opt/cuda/lib64 -o "cudamath" ./cu_test.o -lcuda -lcublas -lcudart
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.0/../../../../lib/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
makefile:32: recipe for target 'cudamath' failed
make: *** [cudamath] Error 1
Is there a way I can do this? I've been crawling through my project settings but I can't seem to find what I'm looking for.
Here's what I did using Nsight Eclipse Edition:
File... new CUDA C/C++ project
In the next dialog, select Shared Library...Empty Project, and give the project a name (let's say it is testlib)
Finish that wizard/dialog. A new testlib project is created in the project explorer on the left
In the project explorer on the left, right click on the project name and create a new folder for your source files
Open that folder and create your new source file. For this, I selected a CUDA C/C++ source file using the CUDA bitreverse "template". This creates a new source file with the bitreverse code in it.
change int main() { in your source file to int myfunc(){
save the source file and build the project. A new libtestlib.so is successfully built.

Compiling native C++ module for Node.js, linking to openSSL/libcrypto fails

I'm using Cygwin/Windows and I'm trying to build a native module for node.js. I intend to make use of the OpenSSL Library. I have installed openssl from the Cygwin package manager.
I have the following lines in my .cc file:
#include <openssl/dh.h>
and
DH* public_dh_key = DH_new();
But when I try to link/compile it with node-waf configure build, I get:
undefined reference to _DH_new
Edit:
Part of the build script:
def build(bld):
ppp= bld.new_task_gen('cxx', 'shlib', 'node_addon')
ppp.cxxflags = ["-g", "-D_FILE_OFFSET_BITS=64", "-D_LARGEFILE_SOURCE", "-Wall", "-L/usr/lib", "-lssl"]
...
(I have tried adding -lcrypto but still get the same result. I have also tried various combinations of "-lssl32","-lssleay32","-llibeay32".)
Edit
Output of the build script:
$ node-waf configure build
Checking for program g++ or c++ : /usr/bin/g++
Checking for program cpp : /usr/bin/cpp
Checking for program ar : /usr/bin/ar
Checking for program ranlib : /usr/bin/ranlib
Checking for g++ : ok
Checking for node path : not found
Checking for node prefix : ok /usr/local
'configure' finished successfully (0.330s)
Waf: Entering directory `/usr/src/build'
[1/2] cxx: ppp.cc -> build/default/ppp_1.o
[2/2] cxx_link: build/default/ppp_1.o -> build/default/ppp.node build/default/libppp.dll.a
Creating library file: default/libppp.dll.a
default/ppp_1.o:/usr/src/build/../ppp.cc:289: undefined reference to `_HMAC'
collect2: ld returned 1 exit status
Waf: Leaving directory `/usr/src/build'
Build failed: -> task failed (err #1):
{task: cxx_link ppp_1.o -> ppp.node,libppp.dll.a}
Edit
I have the header file dh.h in usr/include/openssl
And I have the required files (libssl32.dll, libeay32.dll and ssleay32.dll) in /usr/lib/
The answer
jHackTheRipper answered this and got the credit for it, but the final answer is buried in the comments beneath his answer. So to summarise, the waf mantra is
obj.lib='crypto'
Adding -lcrypto should do the trick.
According to the nm output on my system _DH_new and _HMAC seem to be in the libcrypto (part of OpenSSL) dynamic library :
jhacktheripper#macbook-prolocal:~$ nm /usr/lib/libcrypto.dylib | grep _DH_new
0000000000036360 T _DH_new
0000000000036120 T _DH_new_method
jhacktheripper#macbook-prolocal:~$ nm /usr/lib/libcrypto.dylib | grep HMAC
0000000000090d40 T _HMAC
0000000000090c80 T _HMAC_CTX_cleanup
0000000000090910 T _HMAC_CTX_init
00000000000908c0 T _HMAC_CTX_set_flags
0000000000090940 T _HMAC_Final
0000000000090cc0 T _HMAC_Init
0000000000090a10 T _HMAC_Init_ex
0000000000090a00 T _HMAC_Update