I have the following code from sigpack website
#include "sigpack.h"
using namespace arma;
using namespace sp;
int main()
{
int N = 45191; // Large prime number
FFTW ss(N,FFTW_ESTIMATE);
vec x(N);
cx_vec Sxx(N);
vec P(N);
clock_t tic;
for (int n = 1; n < 5; n++)
{
x.randn();
tic = clock();
Sxx = ss.fft(x);
cout << "FFTW Loop[" << n << "]. Time = " << (clock() - tic)/
double(CLOCKS_PER_SEC) << endl;
x.randn();
tic = clock();
Sxx = fft(x);
cout << " FFT Loop[" << n << "]. Time = " << (clock() - tic) /
double(CLOCKS_PER_SEC) << endl;
}
return 0;
}
I save it as exFFT1
when i build the file under cygwin with g++-6.4.0with command :
g++ -Wall -std=gnu++11 -I/home/budiarjo/sigpack-1.2.4/sigpack/ -I/usr/local/include/ -I/opt/OpenBLAS/include/ -L/opt/OpenBLAS/lib/ -L/usr/local/lib/ -DHAVE_FFTW -lblas -llapack -Dunix exFFT1.cpp -lfftw3 -o exFFT1
The following are the error messages :
/tmp/ccRsp1Bf.o:exFFT1.cpp:(.text.startup+0x1cc): undefined reference to `__emutls_v._ZN4arma23arma_rng_cxx11_instanceE'
/tmp/ccRsp1Bf.o:exFFT1.cpp:(.text.startup+0x242): undefined reference to `__emutls_v._ZN4arma23arma_rng_cxx11_instanceE'
/tmp/ccRsp1Bf.o:exFFT1.cpp:(.text.startup+0x6db): undefined reference to `__emutls_v._ZN4arma23arma_rng_cxx11_instanceE'
/tmp/ccRsp1Bf.o:exFFT1.cpp:(.text.startup+0x752): undefined reference to `__emutls_v._ZN4arma23arma_rng_cxx11_instanceE'
/tmp/ccRsp1Bf.o:exFFT1.cpp:(.text.startup+0x1662): undefined reference to `__emutls_v._ZN4arma23arma_rng_cxx11_instanceE'
/tmp/ccRsp1Bf.o:exFFT1.cpp:(.text.startup+0x16f9): more undefined references to `__emutls_v._ZN4arma23arma_rng_cxx11_instanceE' follow
collect2: error: ld returned 1 exit status
But in Raspberry Pi with g++-4.8, when i build the file with the command
sudo g++ -Wall -std=gnu++11 -I/home/pi/sigpack-1.2.4/sigpack/ -I/opt/OpenBLAS/include/ -L/opt/OpenBLAS/lib/ -DHAVE_FFTW -lopenblas -llapack -Dunix exFFT1.cpp -lfftw3 -o exFFT1
I could build successfully without any error messages.
What could be wrong with my cygwin setting?
Should I replace the g++-6.4.0 in cygwin with g++-4.80? How to downgrade it, since if I compile and do make, the g++-4.80 package, I would get error messages as well because of the usge of gcc/g++-6.40 during the process.
Related
i compliled tensorflow with bazel successfully and got libtensorflow_cc.so and libtensorflow_framework.so. Then i built a c++ binary with those share libraries successfully, but errors occurred when i run the binary, info is like:
F tensorflow/core/framework/variant_op_registry.cc:51] Check failed: existing == nullptr (0x24fc538 vs. nullptr)Unary VariantShapeFn for type_name: int already registered
c++ code:
#include "tensorflow/cc/client/client_session.h"
#include "tensorflow/cc/ops/standard_ops.h"
#include "tensorflow/core/framework/tensor.h"
int main() {
using namespace tensorflow;
using namespace tensorflow::ops;
Scope root = Scope::NewRootScope();auto A = Const(root, { {3.f, 2.f}, {-1.f, 0.f} });
// // Vector b = [3 5
auto b = Const(root, { {3.f, 5.f} });
auto v = MatMul(root.WithOpName("v"), A, b, MatMul::TransposeB(true));
std::vector<Tensor> outputs;
ClientSession session(root);
// Run and fetch v
TF_CHECK_OK(session.Run({v}, &outputs));
// Expect outputs[0] == [19; -3]
LOG(INFO) << outputs[0].matrix<float>();
return 0;
}
i got my c++ binary using cmd:
g++ -std=c++11 test.cpp -o test -I./include -L./lib -L/home/work/chengjy/tools/protobuf/lib -I/home/work/chengjy/tools/tensorflow/eigen/eigen/eigen-eigen-fd6845384b86 -I/home/work/chengjy/tools/protobuf/include -ltensorflow_cc -ltensorflow_framework -lprotobuf -lpthread -ldl -O3 -Wall
did anyone have this problem before?
it seems that i fixed this problem by removing -ltensorflow_framework from the compile cmd.
Note: Added example below and updated title after comment about reproducibility.
We are trying to improve our codebase by supplying attributes to our functions.
on some functions we have added the attribute:
__attribute__ ((warn_unused_result))
At some points we deliberatly put some code that should produce a warning as we do not use the result of the function.
e.g.
shared_ptr<type> functionName() __attribute__ ((warn_unused_result));
functionName(); // this should produce a warning
However no warnings are produced. Are these warnings suppressed by default or are there some other dependencies to make this work.
I found some info here: https://www.linuxquestions.org/questions/programming-9/gcc-warn_unused_result-attribute-917158 via google, but this does not point me in a direction on why it does not work for non-standard features.
As four our setup:
g++ version 4.9.2
Debian version 8.6
enabled warning flags on build:
-Wall -Wextra -Wconversion -Wshadow -Weffc++
Here is an example that reproduces this issue:
#include <iostream>
#include <memory>
std::shared_ptr<std::string> function(int b) __attribute__ ((warn_unused_result));
int other(int b) __attribute__ ((warn_unused_result));
int main()
{
auto lResult = function(3); // not expect warning
std::cout << lResult->c_str() << " is the result" << std::endl;
std::cout << function(4)->c_str() << " is the result too." << std::endl; // not expect warning
function(5); // expect warning but this warning is not given.
auto lOther = other(3); // not expect warning
std::cout << lOther << " is the result" << std::endl;
std::cout << other(4) << " is the result too." << std::endl; // not expect warning
other(5); // expect warning and it is given.
return 0;
}
std::shared_ptr<std::string> function(int b)
{
auto lString = std::make_shared<std::string>("::" + std::to_string(b) + "::");
return lString;
}
int other(int b)
{
return 5 * b;
}
and CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
project(ShowCase)
add_definitions("-std=c++14")
set(CMAKE_CXX_FLAGS_MINSIZEREL "-Wall -Wextra -Wconversion -Wshadow -Weffc++")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -Wall -Wextra -Wconversion -Wshadow -Weffc++")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -Wall -Wextra -Wconversion -Wshadow -Weffc++ ")
set(CMAKE_CXX_FLAGS_DEBUG "-g -Wall -Wextra -Wconversion -Wshadow -Weffc++")
add_executable(ShowCase main.cpp)
Any help or pointers would be much appreciated.
Regards,
Jan Jaap
This evidently is a compiler bug specific to C++ that is present until GCC 6.3
and fixed in GCC 7.1. Upgrading GCC would seem to be your
only solution.
I keep getting the following error when I try to compile an example program from C++ how to program, Deitel and Deitel. I used g++ Fig11_05.cpp -o Fig11_05
I spent hours trying to solve this problem by looking up the Internet and particularly stackoverflow, but with no avail!
I tried using different command line arguments such as -libstd=libc++, -std=c++11, -std=c++14
the error I keep getting is as this:
Undefined symbols for architecture x86_64:
"operator<<(std::__1::basic_ostream >&, PhoneNumber const&)", referenced from:
_main in Fig11_05-1f04bd.o
"operator>>(std::__1::basic_istream >&, PhoneNumber&)", referenced from:
_main in Fig11_05-1f04bd.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The result of g++ -v:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/c++/4.2.1
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
The codes:
// Fig. 11.3: PhoneNumber.h
// PhoneNumber class definition
#ifndef PHONENUMBER_H
#define PHONENUMBER_H
#include <iostream>
#include <string>
class PhoneNumber
{
friend std::ostream& operator<<(std::ostream&, const PhoneNumber&);
friend std::istream &operator>>(std::istream&, PhoneNumber&);
private:
std::string areaCode; // 3-digit area code
std::string exchange; // 3-digit exchange
std::string line; // 4-digit line
}; // end class PhoneNumber
#endif
// Fig. 11.4: PhoneNumber.cpp
// Overloaded stream insertion and stream extraction operators
// for class PhoneNumber.
#include <iomanip>
#include "PhoneNumber.h"
using namespace std;
// overloaded stream insertion operator; cannot be
// a member function if we would like to invoke it with
// cout << somePhoneNumber;
ostream& operator<<(ostream& output, const PhoneNumber& number)
{
output << "Area Code: " << number.areaCode << "\nExchange: "
<< number.exchange << "\nLine: " << number.line << "\n"
<< "(" << number.areaCode << ") " << number.exchange << "-"
<< number.line << "\n";;
return output; // enables cout << a << b << c;
} // end function operator<<
// overloaded stream extraction operator; cannot be
// a member function if we would like to invoke it with
// cin >> somePhoneNumber;
istream& operator>>(istream& input, PhoneNumber& number)
{
input.ignore(); // skip (
input >> setw(3) >> number.areaCode; // input area code
input.ignore(2); // skip ) and space
input >> setw(3) >> number.exchange; // input exchange
input.ignore(); // skip dash (-)
input >> setw(4) >> number.line; // input line
return input; // enables cin >> a >> b >> c;
} // end function operator>>
// Fig. 11.5: fig11_05.cpp
// Demonstrating class PhoneNumber's overloaded stream insertion
// and stream extraction operators.
#include <iostream>
#include "PhoneNumber.h"
using namespace std;
int main()
{
PhoneNumber phone; // create object phone
cout << "Enter phone number in the form (123) 456-7890:" << endl;
// cin >> phone invokes operator>> by implicitly issuing
// the global function call operator>>( cin, phone )
cin >> phone;
cout << "\nThe phone number entered was:\n";
// cout << phone invokes operator<< by implicitly issuing
// the global function call operator<<( cout, phone )
cout << phone << endl;
} // end main
Note: I recently installed then uninstalled CUDA toolkit 8. I needed a newer version of Xcode, so I installed Xcode the newest version 8.2.1, and kept the old version in a different directory just in case. I don't think the problem is with the installation of Xcode though. Also when I installed CUDA I had to set DYLD_LIBRARY_PATH to a directory. However, it might not be the source of the problem! I am just trying to help you figure out the problem to help me fix it :)
Thank you in advance! You are such a good community!
Your attempt to build the program:
g++ Fig11_05.cpp -o Fig11_05
is unsuccessful because you have neglected to compile and link into the
program the code that contains the definitions of the functions:
std::ostream& operator<<(std::ostream& output, const PhoneNumber& number)
and:
std::istream& operator>>(std::istream& input, PhoneNumber& number)
which are called by your program. That is why the linker says:
Undefined symbols for architecture x86_64:
"operator<<(std::__1::basic_ostream >&, PhoneNumber const&)", referenced from: _main in Fig11_05-1f04bd.o
"operator>>(std::__1::basic_istream >&, PhoneNumber&)", referenced from: _main in Fig11_05-1f04bd.o
...
Do this instead:
g++ Fig11_05.cpp PhoneNumber.cpp -o Fig11_05
Or to spell out the process in full:-
Compile source file Fig11_05.cpp to object file Fig11_05.o:
$ g++ -o Fig11_05.o -c Fig11_05.cpp
Compile source file PhoneNumber.cpp to object file PhoneNumber.o:
$ g++ -o PhoneNumber.o -c PhoneNumber.cpp
Link the object files Fig11_05.o and PhoneNumber.o into program Fig11_05
$ g++ -o Fig11_05 Fig11_05.o PhoneNumber.o
You can then run:
./Fig11_05
Here is a fairly good beginner's tutorial
about building C or C++ programs with GCC.
I followed the Setup Guide of another Post and got a working example using XCode as ROOT IDE. Now I tried to include the Minuit2 example code within the same project:
#include "Minuit2/Minuit2Minimizer.h"
#include "Math/Functor.h"
double RosenBrock(const double *xx )
{
const double_t x = xx[0];
const double_t y = xx[1];
const double_t tmp1 = y-x*x;
const double_t tmp2 = 1-x;
return 100*tmp1*tmp1+tmp2*tmp2;
}
int main()
{
// Choose method upon creation between:
// kMigrad, kSimplex, kCombined,
// kScan, kFumili
ROOT::Minuit2::Minuit2Minimizer min ( ROOT::Minuit2::kMigrad );
min.SetMaxFunctionCalls(1000000);
min.SetMaxIterations(100000);
min.SetTolerance(0.001);
ROOT::Math::Functor f(&RosenBrock,2);
double step[2] = {0.01,0.01};
double variable[2] = { -1.,1.2};
min.SetFunction(f);
// Set the free variables to be minimized!
min.SetVariable(0,"x",variable[0], step[0]);
min.SetVariable(1,"y",variable[1], step[1]);
min.Minimize();
const double *xs = min.X();
std::cout << "Minimum: f(" << xs[0] << "," << xs[1] << "): "
<< RosenBrock(xs) << std::endl;
return 0;
}
I tested the code as a root macro and it worked fine, but trying to compile it within XCode yields the following errors:
Undefined symbols for architecture x86_64:
defined symbols for architecture x86_64:
"ROOT::Minuit2::Minuit2Minimizer::SetFunction(ROOT::Math::IBaseFunctionMultiDim const&)", referenced from:
_main in main.o
and serveral more undefined symbols.
What did I do wrong?
I installed ROOT with Macports via
sudo port install root6
and made sure that the variant +minuit2 is installed. Then I added the Search Paths and Linking:
Targets > Build Settings > User Header Search Paths > Debug > /opt/local/libexec/root6/include/root
Targets > Build Settings > Other Linker Flags > Debug > -L/opt/local/libexec/root6/lib/root -lCore -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lMultiProc -lpthread -Wl,-rpath,/opt/local/libexec/root6/lib/root -stdlib=libc++ -lm -ldl
which I got from
root/bin/root-config --libs
To answer this Question myself:
You have to add
-lMinuit2
to the other Flags in your Build settings.
Somehow
root-config --libs
does not automatically add the minuit2 linker.
I'm trying to get started working with Intel's Array Building Blocks, and there seems to only be one tutorial on "Hello World", at http://www.hpc.lsu.edu/training/tutorials/sc10/tutorials/SC10Tutorials/docs/M07/M07.pdf . And I'm not really getting it.
I'm using Visual Studio 2010 and this is the code I got from the above link, kinda.
#include <C:/Program Files/intel/arbb/Beta6/include/arbb.hpp>
//What do I have to do to make just "#include <arbb.hpp>" work?
using namespace arbb;
void my_function(f32& result, f32 input){
std::cout << "Hello, world!" << std::endl;
result = input + 1.0f; //"Error: no operator "+" matches these operands
}
int main(){
typedef closure<void (f32&, f32)> mfc;
mfc a = capture(my_function);
mfc b = call(my_function);
mfc c = call(my_function);
}
What else do I need to do to get "Hello World" working?
There are many samples available in arbb installation path. You can use the visual studio solution files to start with any of the sample. That is the easiest way.
In order to compile and run your own application from scratch, you have to have the include and dependencies set.
On Linux, you can add the path ~/(whatever)/intel/arbb/Beta6/include in the compile option using -I
On Windows, you can do:
set INCLUDE=C:/Program Files/intel/arbb/Beta6/include/arbb.hpp;
Or have a batch script that will ensure all the environment variables are set by default.
--- contents of the batch file ---
SET ARBB_OPT_LEVEL=O3
SET PATH=%ARBB_ROOT%\bin\ia32;%ARBB_ROOT%\bin\ia32\vs%MSVS_VERSION%;%OPENCV_ROOT%\bin;%FFTW_ROOT%;%FREEGLUT_ROOT%;%PTHREADS_ROOT%\lib;%PATH%
---- here is hello world program in arbb ---
#include <arbb.hpp>
void arbb_hello_map(arbb::i32& val)
{
val = val * 2;
}
void arbb_hello(arbb::dense<arbb::i32>& data)
{
using namespace arbb;
map(arbb_hello_map)(data);
}
int main()
{
using namespace arbb;
int size = 5;
dense<i32> data = dense<i32>(size);
range<i32> write_data = data.write_only_range();
for (int i = 0; i < size; ++i)
write_data[i] = i;
arbb::call(arbb_hello)(data);
std::cout << "hello: " << std::endl;
const_range<i32> read_data = data.read_only_range();
for (int i = 0; i < size; ++i)
std::cout <<"data["<<i<<"] = " << read_data[i] <<"\n";
return 0;
}
And compile it using
g++ -m64 -I/home/YOUR_NAME/arbb/install//include -Wall -Werror -O3 -W -Wshadow temp.cpp -o temp -L/home/YOUR_NAME/arbb/install/lib/intel64 -larbb_dev -ltbb -littnotify
Run it using
./temp