Making dynamic library with ***.dylib on Mac OSX and Juce - c++

[Juce][1] is the framework for Audio/Media application
It created the XCode project linking with Juce library.
I start from making test dynamic library.
I exported project to Xcode from Juce and added source.cpp
#include<iostream>
using namespace std;
int helloJuce(){
cout<<"Hello,From Juce!"<<endl;
return 1;
}
Now NewProject.dylib is compiled.
And confirmed that entry point is registered.
$nm NewProject.dylib |grep hello
00000000000021b0 t __Z9helloJucev
in testJuce.cpp
#include
int helloJuce();
int main() {
helloJuce();
std::cout << "Test Finish!\n";
return 0;
}
then, try to compile
$ g++ -o testJuce testJuce.cpp -L ./ -lNewProject
ld: library not found for -lNewProject
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I tested these patterns, but in vain.
cp NewProject.dylib libNewProject.dylib
cp NewProject.dylib libNewProject.so
In generally speaking, lib***.so style is common for dylib??
Does anyone help me?
Any suggestion appreciated.

Related

ld cannot find /lib64/libmvec.so.1 with g++ command

I'm getting started learning c++ project building on linux with simple hello world code.
#include <iostream>
int main(){
std::cout<<"hello,world"<<std::endl;
return 0;
}
When I try to run command
g++ hello.cpp
It fails with:
/opt/rh/devtoolset-6/root/usr/libexec/gcc/x86_64-redhat-linux/6.3.1/ld: cannot find /usr/lib64/libmvec_nonshared.a
/opt/rh/devtoolset-6/root/usr/libexec/gcc/x86_64-redhat-linux/6.3.1/ld: cannot find /lib64/libmvec.so.1
But when I try
gcc -lstdc++ hello.cpp
The compilation is successfully finished and generated executable file a.out.
So what is problem here with g++?

new c++ error with file

I am 100% new at c++ so bear with me :)
I am getting an error with this file and not sure why. any help is appreciated.
#include <iostream>
using namespace std;
int main()
{
cout << "hi" << endl;
return 0;
}
------------ Build: Debug in 1600 (compiler: GNU GCC Compiler)-------------
g++ -o bin/Debug/1600 obj/Debug/main.o obj/Debug/src/test.o obj/Debug/test03.o
duplicate symbol _main in:
obj/Debug/main.o
obj/Debug/test03.o
ld: 1 duplicate symbol for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
From the source files symbols are created. main in the .cpp file becomes _main as a symbol. During linking there can be only one main function, hence only one _main symbol is expected and allowed.
You have three object files that were created:
obj/Debug/main.o which contains main
obj/Debug/src/test.o
obj/Debug/test03.o which also contains main
Probably because you have a .cpp file for each of them and the command line or IDE you are using asked for them all to be compiled.
duplicate symbol _main
The text above is telling you that the linker (trying to make sense of all the compiled object (.o) files) found more than one main.
So the solution is to look at your IDE settings and remove the other files (or at least remove main from the other files) because you are only interested in compiling the one source file.
Its hard to tell what you're running from the question.
Here is how to build a simple C++ program using gcc
In
my_program.cpp
#include <iostream>
using namespace std;
int main()
{
cout << "hi" << endl;
return 0;
}
To compile to object files type
g++ -c my_program.cpp
To link (you'd normally have more files here)
g++ -o my_program my_program.o
So, this isn't very fun so most people use a build system like make, cmake, msbuild or whatever the CLion IDE uses.

Am not able to link a shared library and run executable on mac (Intel tbb)

I was trying to compile and link Intel's tbb into a simple program on my mac, but I keep getting an error saying that the library was linked properly.
dyld: Library not loaded: #rpath/libtbb.dylib
Referenced from:<path>/./a.out
Reason: image not found
Trace/BPT trap: 5
The test program I used has the following code
#include <iostream>
#include <cassert>
#include <tbb/concurrent_queue.h>
int main() {
auto q = tbb::concurrent_queue<int>{};
q.push(1);
auto top_value = int{};
assert(q.try_pop(top_value));
assert(top_value == 1);
assert(q.empty());
return 0;
}
And this is how I built the library (with downloading the library included for your convenience)
curl -OL https://www.threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb2017_20170118oss_src.tgz
tar -xzvf tbb2017_20170118oss_src.tgz
mv tbb2017_20170118oss tbb
rm tbb2017_20170118oss_src.tgz
cd tbb
make tbb
mv build/*_release build/tbb_release
And I tried to compile the program with this command
g+++ another.cpp -I tbb/include -L tbb/build/tbb_release -ltbb -ldl
And then on running the program I get the error above. Any ideas on how I can go about fixing this?
My compiler's version is clang-800.0.42.1 and the operating system I am running is 10.11.5
Thanks!

Getting error clang: error: linker command failed with exit code 1 (use -v to see invocation) while compile C++ file from terminal

I'm getting this error
clang: error: linker command failed with exit code 1 (use -v to see invocation)
while i'm compiling simple cpp file from terminal
gcc hello.cpp
here's the content of hello.cpp file:
#include <iostream>
using namespace std;
// main() is where program execution begins.
int main()
{
cout << "Hello World"; // prints Hello World
return 0;
}
I think it might conflict with XCode compiler?
gcc hello.cpp should be g++ hello.cpp
gcc is for compiling and linking C code, while g++ is used for C++ code as you have it.
I think it might conflict with XCode compiler?
No. The point is that the gcc command is also able to compile C++ code detected from the .cpp file extension, though the libstdc++.a won't be linked automatically.

Simple project won't compile

I'm still having issues with an ongoing project that just won't compile. I've narrowed it down to the Includes but can't figure out what is going on. I've read that i need to add a WinMain entry point but that doesnt add up - I have classmates that didnt encounter this shit error at all.
So I've created a new empty project:
#include <cstdlib> //include c library
//using namespace std;
//using namespace cv;
namespace sp {
int main() {
return 0;
}
}
With the following includes:
Under GCC C++ Compiler Includes:
C:\Users\Amit\Desktop\opencv\build\include
C:\opencv_contrib-3.0.0\modules\xfeatures2d\include
Under MinGW C++ Linker Libraries:
libopencv_core310
libopencv_imgcodecs310
libopencv_imgproc310
libopencv_xfeatures2d310
libopencv_features2d310
libopencv_highgui310
Under MinGW C++ Linker Library search path:
C:\Users\Amit\Desktop\opencv\build\x86\mingw\lib
Still, without calling any function from those libraries, I'm getting this error:
09:45:43 **** Incremental Build of configuration Debug for project testing ****
Info: Internal Builder is used for build
g++ "-IC:\\opencv_contrib-3.0.0\\modules\\xfeatures2d\\include" "-IC:\\Users\\Amit\\Desktop\\opencv\\build\\include" -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\testing.o" "..\\src\\testing.cpp"
g++ "-LC:\\Users\\Amit\\Desktop\\opencv\\build\\x86\\mingw\\lib" -o testing.exe "src\\testing.o" -llibopencv_core310 -llibopencv_imgcodecs310 -llibopencv_imgproc310 -llibopencv_xfeatures2d310 -llibopencv_features2d310 -llibopencv_highgui310
c:/mingw/bin/../lib/gcc/mingw32/4.9.3/../../../libmingw32.a(main.o):(.text.startup+0xa7): undefined reference to `WinMain#16'
collect2.exe: error: ld returned 1 exit status
09:45:43 Build Finished (took 396ms)
Can anyone save me?
Thanks,
Amit.
When you create an executable the linker expects a function named main in the global namespace. You have placed the function inside a namespace instead of the global namespace so the linker will not find it.
So either move your main outside of the sp namespace or tell the linker where the function is (at least that is possible with MS linker but not sure how it is done with g++).
namespace sp {
int main() {
return 0;
}
}
declares an sp::main function, not main. This leaves you without a main function to serve as the program entry point.
Solution: Remove main from the sp namespace.
int main() {
return 0;
}