I am trying to create executable of following code taken from here:
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/imgcodecs.hpp>
using namespace cv;
using namespace std;
// Driver code
int main(int argc, char** argv)
{
// Read the image file as // imread("default.jpg");
Mat image = imread("barchart.png", IMREAD_GRAYSCALE);
// Error Handling
if (image.empty()) {
cout << "Image File Not Found" << endl;
// wait for any key press
cin.get();
return -1;
}
// Show Image inside a window with the name provided
imshow("Window Name", image);
// Wait for any keystroke
waitKey(0);
return 0;
}
It compiles all right with command g++ showimage.cpp -c -I /usr/include/opencv4 and creates an showimage.o file
However, following command to link it gives error:
g++ showimage.o -l:libopencv_imgcodecs.a
...
... (lot of output)
/usr/bin/ld: showimage.o: in function `main':
showimage.cpp:(.text+0x83): undefined reference to `cv::Mat::empty() const'
/usr/bin/ld: showimage.cpp:(.text+0x10e): undefined reference to `cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
/usr/bin/ld: showimage.cpp:(.text+0x13c): undefined reference to `cv::waitKey(int)'
/usr/bin/ld: showimage.cpp:(.text+0x150): undefined reference to `cv::Mat::~Mat()'
/usr/bin/ld: showimage.cpp:(.text+0x1c2): undefined reference to `cv::Mat::~Mat()'
collect2: error: ld returned 1 exit status
I also tried following option:
g++ showimage.o -L /usr/lib/x86_64-linux-gnu
g++ showimage.o -L libopencv
g++ showimage.o -L opencv
But none is not working.
Where is the problem and how can it be solved?
The undefined reference is generally a linker error. I feel like the error is because of my compilation of mlpack rather than code but I do not know how to track it down or if my assumption is correct. Or if it is a bug and there is a work around.
I have written the code using this as reference - mlpack documentation
-Forgive my includes, I copied them from another file directly-
The error comes up only due to the Train statement, everything else worked fine. I used armadillo in other places and was working fine with complex data and matrix operations like eigen values generation, transpose of vectors, vector operations etc. So, I know that the error probably isn't in armadillo.
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <vector>
#include <complex>
#include <vector>
#include <map>
#include <fstream>
#include <string>
#include <filesystem>
#include <sstream>
#include <utility>
#include <algorithm>
#include <random>
#include <execution>
#include <mlpack/prereqs.hpp>
#include <mlpack/core.hpp>
#include <mlpack/core/data/split_data.hpp>
#include <mlpack/methods/ann/layer/layer.hpp>
#include <mlpack/methods/ann/ffn.hpp>
namespace fs = std::filesystem;
constexpr auto PI = 3.14159265f;
using namespace std;
using namespace std::complex_literals;
using namespace mlpack;
using namespace mlpack::ann;
int main() {
arma::mat trainData;
trainData = {
{1.0,11.0,21.0,31.0},
{2.0,12.0,22.0,32.0},
{3.0,13.0,23.0,33.0},
{4.0,14.0,24.0,34.0},
{6.0,16.0,26.0,36.0},
{7.0,17.0,27.0,37.0},
{8.0,18.0,28.0,38.0},
{9.0,19.0,29.0,39.0}
};
arma::mat trainLabel;
trainLabel = {1.0,2.0,3.0,4.0} ;
trainData.print();
trainLabel.print();
FFN<> model;
model.Add<Linear<> >(trainData.n_rows, 12);
model.Add<SigmoidLayer<> >();
model.Add<Linear<> >(12, 3);
model.Add<LogSoftMax<> >();
model.Train(trainData, trainLabel);
}
I run the code using the below command
g++ -O3 minimumReproducableCodeForMLError.cpp -Iarmadillo/include -Imlpack/include/ -Iboost/include -Larmadillo/lib -Lblas/lib/ -Lboost/lib -Llapack/ -Lmlpack/lib -Lopenblas/lib -Iopenblas/include -fopenmp -larmadillo -lmlpack -std=c++2a -w -o minCode.o
I tried splitting the g++ command into -c and compile the object file after that with linker. It failed at the linker part. The compile part just gives me depreceated-declarations warning from boost library.
and this is the error I get -
/usr/bin/ld: /tmp/ccNWv7em.o: in function `arma::arma_rng::randn<double>::fill(double*, unsigned long long)':
minimumReproducableCodeForMLError.cpp:(.text._ZN4arma8arma_rng5randnIdE4fillEPdy[_ZN4arma8arma_rng5randnIdE4fillEPdy]+0x56): undefined reference to `arma::mt19937_64_instance'
/usr/bin/ld: minimumReproducableCodeForMLError.cpp:(.text._ZN4arma8arma_rng5randnIdE4fillEPdy[_ZN4arma8arma_rng5randnIdE4fillEPdy]+0x71): undefined reference to `TLS init function for arma::mt19937_64_instance'
/usr/bin/ld: minimumReproducableCodeForMLError.cpp:(.text._ZN4arma8arma_rng5randnIdE4fillEPdy[_ZN4arma8arma_rng5randnIdE4fillEPdy]+0x1e0): undefined reference to `TLS init function for arma::mt19937_64_instance'
/usr/bin/ld: minimumReproducableCodeForMLError.cpp:(.text._ZN4arma8arma_rng5randnIdE4fillEPdy[_ZN4arma8arma_rng5randnIdE4fillEPdy]+0x1e7): undefined reference to `arma::mt19937_64_instance'
/usr/bin/ld: /tmp/ccNWv7em.o: in function `void mlpack::math::ShuffleData<arma::Mat<double>, arma::Mat<double> >(arma::Mat<double> const&, arma::Mat<double> const&, arma::Mat<double>&, arma::Mat<double>&, std::enable_if<!arma::is_SpMat<arma::Mat<double> >::value, void>::type const*, std::enable_if<!arma::is_Cube<arma::Mat<double> >::value, void>::type const*)':
minimumReproducableCodeForMLError.cpp:(.text._ZN6mlpack4math11ShuffleDataIN4arma3MatIdEES4_EEvRKT_RKT0_RS5_RS8_PKNSt9enable_ifIXntsrNS2_8is_SpMatIS5_EE5valueEvE4typeEPKNSD_IXntsrNS2_7is_CubeIS5_EE5valueEvE4typeE[_ZN6mlpack4math11ShuffleDataIN4arma3MatIdEES4_EEvRKT_RKT0_RS5_RS8_PKNSt9enable_ifIXntsrNS2_8is_SpMatIS5_EE5valueEvE4typeEPKNSD_IXntsrNS2_7is_CubeIS5_EE5valueEvE4typeE]+0x31b): undefined reference to `TLS init function for arma::mt19937_64_instance'
/usr/bin/ld: minimumReproducableCodeForMLError.cpp:(.text._ZN6mlpack4math11ShuffleDataIN4arma3MatIdEES4_EEvRKT_RKT0_RS5_RS8_PKNSt9enable_ifIXntsrNS2_8is_SpMatIS5_EE5valueEvE4typeEPKNSD_IXntsrNS2_7is_CubeIS5_EE5valueEvE4typeE[_ZN6mlpack4math11ShuffleDataIN4arma3MatIdEES4_EEvRKT_RKT0_RS5_RS8_PKNSt9enable_ifIXntsrNS2_8is_SpMatIS5_EE5valueEvE4typeEPKNSD_IXntsrNS2_7is_CubeIS5_EE5valueEvE4typeE]+0x322): undefined reference to `arma::mt19937_64_instance'
/usr/bin/ld: /tmp/ccNWv7em.o: in function `_ZN6mlpack3ann21NetworkInitializationINS0_20RandomInitializationEJEE10InitializeIdEEvRKSt6vectorIN5boost7variantIPNS0_18AdaptiveMaxPoolingIN4arma3MatIdEESB_EEJPNS0_19AdaptiveMeanPoolingISB_SB_EEPNS0_3AddISB_SB_EEPNS0_8AddMergeISB_SB_JEEEPNS0_12AlphaDropoutISB_SB_EEPNS0_17AtrousConvolutionINS0_16NaiveConvolutionINS0_16ValidConvolutionEEENSR_INS0_15FullConvolutionEEEST_SB_SB_EEPNS0_9BaseLayerINS0_16LogisticFunctionESB_SB_EEPNSY_INS0_16IdentityFunctionESB_SB_EEPNSY_INS0_12TanhFunctionESB_SB_EEPNSY_INS0_16SoftplusFunctionESB_SB_EEPNSY_INS0_17RectifierFunctionESB_SB_EEPNS0_9BatchNormISB_SB_EEPNS0_21BilinearInterpolationISB_SB_EEPNS0_4CELUISB_SB_EEPNS0_6ConcatISB_SB_JEEEPNS0_11ConcatenateISB_SB_EEPNS0_17ConcatPerformanceINS0_21NegativeLogLikelihoodISB_SB_EESB_SB_EEPNS0_8ConstantISB_SB_EEPNS0_11ConvolutionIST_SV_ST_SB_SB_EEPNS0_5CReLUISB_SB_EEPNS0_11DropConnectISB_SB_EEPNS0_7DropoutISB_SB_EEPNS0_3ELUISB_SB_EEPNS0_8FastLSTMISB_SB_EEPNS0_12FlexibleReLUISB_SB_EEPNS0_3GRUISB_SB_EEPNS0_8HardTanHISB_SB_EEPNS0_4JoinISB_SB_EEPNS0_9LayerNormISB_SB_EEPNS0_9LeakyReLUISB_SB_EEPNS0_6LinearISB_SB_NS0_13NoRegularizerEEEPNS0_12LinearNoBiasISB_SB_S32_EEPNS0_10LogSoftMaxISB_SB_EEPNS0_6LookupISB_SB_EEPNS0_4LSTMISB_SB_EEPNS0_10MaxPoolingISB_SB_EEPNS0_11MeanPoolingISB_SB_EEPNS0_23MiniBatchDiscriminationISB_SB_EEPNS0_16MultiplyConstantISB_SB_EEPNS0_13MultiplyMergeISB_SB_JEEEPS1V_PNS0_11NoisyLinearISB_SB_EEPNS0_7PaddingISB_SB_EEPNS0_5PReLUISB_SB_EEPNS0_7SoftmaxISB_SB_EEPNS0_14SpatialDropoutISB_SB_EEPNS0_21TransposedConvolutionIST_ST_ST_SB_SB_EEPNS0_10WeightNormISB_SB_JEEENS7_IPNS0_8Linear3DISB_SB_S32_EEJPNS0_7GlimpseISB_SB_EEPNS0_7HighwayISB_SB_JEEEPNS0_18MultiheadAttentionISB_SB_S32_EEPNS0_9RecurrentISB_SB_JEEEPNS0_18RecurrentAttentionISB_SB_EEPNS0_15ReinforceNormalISB_SB_EEPNS0_17ReparametrizationISB_SB_EEPNS0_6SelectISB_SB_EEPNS0_10SequentialISB_SB_Lb0EJEEEPNS59_ISB_SB_Lb1EJEEEPNS0_7SubviewISB_SB_EEPNS0_13VRClassRewardISB_SB_EEPNS0_16VirtualBatchNormISB_SB_EEPNS0_3RBFISB_SB_NS0_16GaussianFunctionEEEPNSY_IS5O_SB_SB_EEPNS0_18PositionalEncodingISB_SB_EEEEEEEESaIS5X_EERNSA_IT_EEm':
minimumReproducableCodeForMLError.cpp:(.text._ZN6mlpack3ann21NetworkInitializationINS0_20RandomInitializationEJEE10InitializeIdEEvRKSt6vectorIN5boost7variantIPNS0_18AdaptiveMaxPoolingIN4arma3MatIdEESB_EEJPNS0_19AdaptiveMeanPoolingISB_SB_EEPNS0_3AddISB_SB_EEPNS0_8AddMergeISB_SB_JEEEPNS0_12AlphaDropoutISB_SB_EEPNS0_17AtrousConvolutionINS0_16NaiveConvolutionINS0_16ValidConvolutionEEENSR_INS0_15FullConvolutionEEEST_SB_SB_EEPNS0_9BaseLayerINS0_16LogisticFunctionESB_SB_EEPNSY_INS0_16IdentityFunctionESB_SB_EEPNSY_INS0_12TanhFunctionESB_SB_EEPNSY_INS0_16SoftplusFunctionESB_SB_EEPNSY_INS0_17RectifierFunctionESB_SB_EEPNS0_9BatchNormISB_SB_EEPNS0_21BilinearInterpolationISB_SB_EEPNS0_4CELUISB_SB_EEPNS0_6ConcatISB_SB_JEEEPNS0_11ConcatenateISB_SB_EEPNS0_17ConcatPerformanceINS0_21NegativeLogLikelihoodISB_SB_EESB_SB_EEPNS0_8ConstantISB_SB_EEPNS0_11ConvolutionIST_SV_ST_SB_SB_EEPNS0_5CReLUISB_SB_EEPNS0_11DropConnectISB_SB_EEPNS0_7DropoutISB_SB_EEPNS0_3ELUISB_SB_EEPNS0_8FastLSTMISB_SB_EEPNS0_12FlexibleReLUISB_SB_EEPNS0_3GRUISB_SB_EEPNS0_8HardTanHISB_SB_EEPNS0_4JoinISB_SB_EEPNS0_9LayerNormISB_SB_EEPNS0_9LeakyReLUISB_SB_EEPNS0_6LinearISB_SB_NS0_13NoRegularizerEEEPNS0_12LinearNoBiasISB_SB_S32_EEPNS0_10LogSoftMaxISB_SB_EEPNS0_6LookupISB_SB_EEPNS0_4LSTMISB_SB_EEPNS0_10MaxPoolingISB_SB_EEPNS0_11MeanPoolingISB_SB_EEPNS0_23MiniBatchDiscriminationISB_SB_EEPNS0_16MultiplyConstantISB_SB_EEPNS0_13MultiplyMergeISB_SB_JEEEPS1V_PNS0_11NoisyLinearISB_SB_EEPNS0_7PaddingISB_SB_EEPNS0_5PReLUISB_SB_EEPNS0_7SoftmaxISB_SB_EEPNS0_14SpatialDropoutISB_SB_EEPNS0_21TransposedConvolutionIST_ST_ST_SB_SB_EEPNS0_10WeightNormISB_SB_JEEENS7_IPNS0_8Linear3DISB_SB_S32_EEJPNS0_7GlimpseISB_SB_EEPNS0_7HighwayISB_SB_JEEEPNS0_18MultiheadAttentionISB_SB_S32_EEPNS0_9RecurrentISB_SB_JEEEPNS0_18RecurrentAttentionISB_SB_EEPNS0_15ReinforceNormalISB_SB_EEPNS0_17ReparametrizationISB_SB_EEPNS0_6SelectISB_SB_EEPNS0_10SequentialISB_SB_Lb0EJEEEPNS59_ISB_SB_Lb1EJEEEPNS0_7SubviewISB_SB_EEPNS0_13VRClassRewardISB_SB_EEPNS0_16VirtualBatchNormISB_SB_EEPNS0_3RBFISB_SB_NS0_16GaussianFunctionEEEPNSY_IS5O_SB_SB_EEPNS0_18PositionalEncodingISB_SB_EEEEEEEESaIS5X_EERNSA_IT_EEm[_ZN6mlpack3ann21NetworkInitializationINS0_20RandomInitializationEJEE10InitializeIdEEvRKSt6vectorIN5boost7variantIPNS0_18AdaptiveMaxPoolingIN4arma3MatIdEESB_EEJPNS0_19AdaptiveMeanPoolingISB_SB_EEPNS0_3AddISB_SB_EEPNS0_8AddMergeISB_SB_JEEEPNS0_12AlphaDropoutISB_SB_EEPNS0_17AtrousConvolutionINS0_16NaiveConvolutionINS0_16ValidConvolutionEEENSR_INS0_15FullConvolutionEEEST_SB_SB_EEPNS0_9BaseLayerINS0_16LogisticFunctionESB_SB_EEPNSY_INS0_16IdentityFunctionESB_SB_EEPNSY_INS0_12TanhFunctionESB_SB_EEPNSY_INS0_16SoftplusFunctionESB_SB_EEPNSY_INS0_17RectifierFunctionESB_SB_EEPNS0_9BatchNormISB_SB_EEPNS0_21BilinearInterpolationISB_SB_EEPNS0_4CELUISB_SB_EEPNS0_6ConcatISB_SB_JEEEPNS0_11ConcatenateISB_SB_EEPNS0_17ConcatPerformanceINS0_21NegativeLogLikelihoodISB_SB_EESB_SB_EEPNS0_8ConstantISB_SB_EEPNS0_11ConvolutionIST_SV_ST_SB_SB_EEPNS0_5CReLUISB_SB_EEPNS0_11DropConnectISB_SB_EEPNS0_7DropoutISB_SB_EEPNS0_3ELUISB_SB_EEPNS0_8FastLSTMISB_SB_EEPNS0_12FlexibleReLUISB_SB_EEPNS0_3GRUISB_SB_EEPNS0_8HardTanHISB_SB_EEPNS0_4JoinISB_SB_EEPNS0_9LayerNormISB_SB_EEPNS0_9LeakyReLUISB_SB_EEPNS0_6LinearISB_SB_NS0_13NoRegularizerEEEPNS0_12LinearNoBiasISB_SB_S32_EEPNS0_10LogSoftMaxISB_SB_EEPNS0_6LookupISB_SB_EEPNS0_4LSTMISB_SB_EEPNS0_10MaxPoolingISB_SB_EEPNS0_11MeanPoolingISB_SB_EEPNS0_23MiniBatchDiscriminationISB_SB_EEPNS0_16MultiplyConstantISB_SB_EEPNS0_13MultiplyMergeISB_SB_JEEEPS1V_PNS0_11NoisyLinearISB_SB_EEPNS0_7PaddingISB_SB_EEPNS0_5PReLUISB_SB_EEPNS0_7SoftmaxISB_SB_EEPNS0_14SpatialDropoutISB_SB_EEPNS0_21TransposedConvolutionIST_ST_ST_SB_SB_EEPNS0_10WeightNormISB_SB_JEEENS7_IPNS0_8Linear3DISB_SB_S32_EEJPNS0_7GlimpseISB_SB_EEPNS0_7HighwayISB_SB_JEEEPNS0_18MultiheadAttentionISB_SB_S32_EEPNS0_9RecurrentISB_SB_JEEEPNS0_18RecurrentAttentionISB_SB_EEPNS0_15ReinforceNormalISB_SB_EEPNS0_17ReparametrizationISB_SB_EEPNS0_6SelectISB_SB_EEPNS0_10SequentialISB_SB_Lb0EJEEEPNS59_ISB_SB_Lb1EJEEEPNS0_7SubviewISB_SB_EEPNS0_13VRClassRewardISB_SB_EEPNS0_16VirtualBatchNormISB_SB_EEPNS0_3RBFISB_SB_NS0_16GaussianFunctionEEEPNSY_IS5O_SB_SB_EEPNS0_18PositionalEncodingISB_SB_EEEEEEEESaIS5X_EERNSA_IT_EEm]+0x248): undefined reference to `TLS init function for arma::mt19937_64_instance'
/usr/bin/ld: minimumReproducableCodeForMLError.cpp:(.text._ZN6mlpack3ann21NetworkInitializationINS0_20RandomInitializationEJEE10InitializeIdEEvRKSt6vectorIN5boost7variantIPNS0_18AdaptiveMaxPoolingIN4arma3MatIdEESB_EEJPNS0_19AdaptiveMeanPoolingISB_SB_EEPNS0_3AddISB_SB_EEPNS0_8AddMergeISB_SB_JEEEPNS0_12AlphaDropoutISB_SB_EEPNS0_17AtrousConvolutionINS0_16NaiveConvolutionINS0_16ValidConvolutionEEENSR_INS0_15FullConvolutionEEEST_SB_SB_EEPNS0_9BaseLayerINS0_16LogisticFunctionESB_SB_EEPNSY_INS0_16IdentityFunctionESB_SB_EEPNSY_INS0_12TanhFunctionESB_SB_EEPNSY_INS0_16SoftplusFunctionESB_SB_EEPNSY_INS0_17RectifierFunctionESB_SB_EEPNS0_9BatchNormISB_SB_EEPNS0_21BilinearInterpolationISB_SB_EEPNS0_4CELUISB_SB_EEPNS0_6ConcatISB_SB_JEEEPNS0_11ConcatenateISB_SB_EEPNS0_17ConcatPerformanceINS0_21NegativeLogLikelihoodISB_SB_EESB_SB_EEPNS0_8ConstantISB_SB_EEPNS0_11ConvolutionIST_SV_ST_SB_SB_EEPNS0_5CReLUISB_SB_EEPNS0_11DropConnectISB_SB_EEPNS0_7DropoutISB_SB_EEPNS0_3ELUISB_SB_EEPNS0_8FastLSTMISB_SB_EEPNS0_12FlexibleReLUISB_SB_EEPNS0_3GRUISB_SB_EEPNS0_8HardTanHISB_SB_EEPNS0_4JoinISB_SB_EEPNS0_9LayerNormISB_SB_EEPNS0_9LeakyReLUISB_SB_EEPNS0_6LinearISB_SB_NS0_13NoRegularizerEEEPNS0_12LinearNoBiasISB_SB_S32_EEPNS0_10LogSoftMaxISB_SB_EEPNS0_6LookupISB_SB_EEPNS0_4LSTMISB_SB_EEPNS0_10MaxPoolingISB_SB_EEPNS0_11MeanPoolingISB_SB_EEPNS0_23MiniBatchDiscriminationISB_SB_EEPNS0_16MultiplyConstantISB_SB_EEPNS0_13MultiplyMergeISB_SB_JEEEPS1V_PNS0_11NoisyLinearISB_SB_EEPNS0_7PaddingISB_SB_EEPNS0_5PReLUISB_SB_EEPNS0_7SoftmaxISB_SB_EEPNS0_14SpatialDropoutISB_SB_EEPNS0_21TransposedConvolutionIST_ST_ST_SB_SB_EEPNS0_10WeightNormISB_SB_JEEENS7_IPNS0_8Linear3DISB_SB_S32_EEJPNS0_7GlimpseISB_SB_EEPNS0_7HighwayISB_SB_JEEEPNS0_18MultiheadAttentionISB_SB_S32_EEPNS0_9RecurrentISB_SB_JEEEPNS0_18RecurrentAttentionISB_SB_EEPNS0_15ReinforceNormalISB_SB_EEPNS0_17ReparametrizationISB_SB_EEPNS0_6SelectISB_SB_EEPNS0_10SequentialISB_SB_Lb0EJEEEPNS59_ISB_SB_Lb1EJEEEPNS0_7SubviewISB_SB_EEPNS0_13VRClassRewardISB_SB_EEPNS0_16VirtualBatchNormISB_SB_EEPNS0_3RBFISB_SB_NS0_16GaussianFunctionEEEPNSY_IS5O_SB_SB_EEPNS0_18PositionalEncodingISB_SB_EEEEEEEESaIS5X_EERNSA_IT_EEm[_ZN6mlpack3ann21NetworkInitializationINS0_20RandomInitializationEJEE10InitializeIdEEvRKSt6vectorIN5boost7variantIPNS0_18AdaptiveMaxPoolingIN4arma3MatIdEESB_EEJPNS0_19AdaptiveMeanPoolingISB_SB_EEPNS0_3AddISB_SB_EEPNS0_8AddMergeISB_SB_JEEEPNS0_12AlphaDropoutISB_SB_EEPNS0_17AtrousConvolutionINS0_16NaiveConvolutionINS0_16ValidConvolutionEEENSR_INS0_15FullConvolutionEEEST_SB_SB_EEPNS0_9BaseLayerINS0_16LogisticFunctionESB_SB_EEPNSY_INS0_16IdentityFunctionESB_SB_EEPNSY_INS0_12TanhFunctionESB_SB_EEPNSY_INS0_16SoftplusFunctionESB_SB_EEPNSY_INS0_17RectifierFunctionESB_SB_EEPNS0_9BatchNormISB_SB_EEPNS0_21BilinearInterpolationISB_SB_EEPNS0_4CELUISB_SB_EEPNS0_6ConcatISB_SB_JEEEPNS0_11ConcatenateISB_SB_EEPNS0_17ConcatPerformanceINS0_21NegativeLogLikelihoodISB_SB_EESB_SB_EEPNS0_8ConstantISB_SB_EEPNS0_11ConvolutionIST_SV_ST_SB_SB_EEPNS0_5CReLUISB_SB_EEPNS0_11DropConnectISB_SB_EEPNS0_7DropoutISB_SB_EEPNS0_3ELUISB_SB_EEPNS0_8FastLSTMISB_SB_EEPNS0_12FlexibleReLUISB_SB_EEPNS0_3GRUISB_SB_EEPNS0_8HardTanHISB_SB_EEPNS0_4JoinISB_SB_EEPNS0_9LayerNormISB_SB_EEPNS0_9LeakyReLUISB_SB_EEPNS0_6LinearISB_SB_NS0_13NoRegularizerEEEPNS0_12LinearNoBiasISB_SB_S32_EEPNS0_10LogSoftMaxISB_SB_EEPNS0_6LookupISB_SB_EEPNS0_4LSTMISB_SB_EEPNS0_10MaxPoolingISB_SB_EEPNS0_11MeanPoolingISB_SB_EEPNS0_23MiniBatchDiscriminationISB_SB_EEPNS0_16MultiplyConstantISB_SB_EEPNS0_13MultiplyMergeISB_SB_JEEEPS1V_PNS0_11NoisyLinearISB_SB_EEPNS0_7PaddingISB_SB_EEPNS0_5PReLUISB_SB_EEPNS0_7SoftmaxISB_SB_EEPNS0_14SpatialDropoutISB_SB_EEPNS0_21TransposedConvolutionIST_ST_ST_SB_SB_EEPNS0_10WeightNormISB_SB_JEEENS7_IPNS0_8Linear3DISB_SB_S32_EEJPNS0_7GlimpseISB_SB_EEPNS0_7HighwayISB_SB_JEEEPNS0_18MultiheadAttentionISB_SB_S32_EEPNS0_9RecurrentISB_SB_JEEEPNS0_18RecurrentAttentionISB_SB_EEPNS0_15ReinforceNormalISB_SB_EEPNS0_17ReparametrizationISB_SB_EEPNS0_6SelectISB_SB_EEPNS0_10SequentialISB_SB_Lb0EJEEEPNS59_ISB_SB_Lb1EJEEEPNS0_7SubviewISB_SB_EEPNS0_13VRClassRewardISB_SB_EEPNS0_16VirtualBatchNormISB_SB_EEPNS0_3RBFISB_SB_NS0_16GaussianFunctionEEEPNSY_IS5O_SB_SB_EEPNS0_18PositionalEncodingISB_SB_EEEEEEEESaIS5X_EERNSA_IT_EEm]+0x24f): undefined reference to `arma::mt19937_64_instance'
/usr/bin/ld: /tmp/ccNWv7em.o: in function `void mlpack::ann::Dropout<arma::Mat<double>, arma::Mat<double> >::Forward<double>(arma::Mat<double> const&, arma::Mat<double>&)':
minimumReproducableCodeForMLError.cpp:(.text._ZN6mlpack3ann7DropoutIN4arma3MatIdEES4_E7ForwardIdEEvRKNS3_IT_EERS8_[_ZN6mlpack3ann7DropoutIN4arma3MatIdEES4_E7ForwardIdEEvRKNS3_IT_EERS8_]+0xd7): undefined reference to `TLS init function for arma::mt19937_64_instance'
/usr/bin/ld: minimumReproducableCodeForMLError.cpp:(.text._ZN6mlpack3ann7DropoutIN4arma3MatIdEES4_E7ForwardIdEEvRKNS3_IT_EERS8_[_ZN6mlpack3ann7DropoutIN4arma3MatIdEES4_E7ForwardIdEEvRKNS3_IT_EERS8_]+0xe7): undefined reference to `arma::mt19937_64_instance'
/usr/bin/ld: /tmp/ccNWv7em.o: in function `void mlpack::ann::SpatialDropout<arma::Mat<double>, arma::Mat<double> >::Forward<double>(arma::Mat<double> const&, arma::Mat<double>&)':
minimumReproducableCodeForMLError.cpp:(.text._ZN6mlpack3ann14SpatialDropoutIN4arma3MatIdEES4_E7ForwardIdEEvRKNS3_IT_EERS8_[_ZN6mlpack3ann14SpatialDropoutIN4arma3MatIdEES4_E7ForwardIdEEvRKNS3_IT_EERS8_]+0x386): undefined reference to `TLS init function for arma::mt19937_64_instance'
/usr/bin/ld: minimumReproducableCodeForMLError.cpp:(.text._ZN6mlpack3ann14SpatialDropoutIN4arma3MatIdEES4_E7ForwardIdEEvRKNS3_IT_EERS8_[_ZN6mlpack3ann14SpatialDropoutIN4arma3MatIdEES4_E7ForwardIdEEvRKNS3_IT_EERS8_]+0x38d): undefined reference to `arma::mt19937_64_instance'
/usr/bin/ld: /tmp/ccNWv7em.o: in function `void mlpack::ann::AlphaDropout<arma::Mat<double>, arma::Mat<double> >::Forward<double>(arma::Mat<double> const&, arma::Mat<double>&)':
minimumReproducableCodeForMLError.cpp:(.text._ZN6mlpack3ann12AlphaDropoutIN4arma3MatIdEES4_E7ForwardIdEEvRKNS3_IT_EERS8_[_ZN6mlpack3ann12AlphaDropoutIN4arma3MatIdEES4_E7ForwardIdEEvRKNS3_IT_EERS8_]+0xf4): undefined reference to `TLS init function for arma::mt19937_64_instance'
/usr/bin/ld: minimumReproducableCodeForMLError.cpp:(.text._ZN6mlpack3ann12AlphaDropoutIN4arma3MatIdEES4_E7ForwardIdEEvRKNS3_IT_EERS8_[_ZN6mlpack3ann12AlphaDropoutIN4arma3MatIdEES4_E7ForwardIdEEvRKNS3_IT_EERS8_]+0x104): undefined reference to `arma::mt19937_64_instance'
/usr/bin/ld: /tmp/ccNWv7em.o: in function `void mlpack::ann::DropConnect<arma::Mat<double>, arma::Mat<double> >::Forward<double>(arma::Mat<double> const&, arma::Mat<double>&)':
minimumReproducableCodeForMLError.cpp:(.text._ZN6mlpack3ann11DropConnectIN4arma3MatIdEES4_E7ForwardIdEEvRKNS3_IT_EERS8_[_ZN6mlpack3ann11DropConnectIN4arma3MatIdEES4_E7ForwardIdEEvRKNS3_IT_EERS8_]+0x16c): undefined reference to `TLS init function for arma::mt19937_64_instance'
/usr/bin/ld: minimumReproducableCodeForMLError.cpp:(.text._ZN6mlpack3ann11DropConnectIN4arma3MatIdEES4_E7ForwardIdEEvRKNS3_IT_EERS8_[_ZN6mlpack3ann11DropConnectIN4arma3MatIdEES4_E7ForwardIdEEvRKNS3_IT_EERS8_]+0x17c): undefined reference to `arma::mt19937_64_instance'
collect2: error: ld returned 1 exit status
Edit 1:
As per request in comments below, I tried running nm tool on my output file, armadillo, and mlpack and this is the output.
So, I tired it on armadillo and mlpack
I got some values
I did nm --demangle libarmadillo.so.10.7.4 | grep arma::mt and I got
00000000000008 B arma::mt19937_64_instance
00000000000cdd0 T TLS init function for arma::mt19937_64_instance
and for libmlpack.so.3.4 I got
U arma::mat19937_64_instance
000000199730 W void arma::op_stddev::apply<arma::Mat..........................> //This line doesn't have mat19937_64
U TLS init function for arma::mt19937_64_instance
I download and build leveldb according to this README, and then properly add libleveldb.a and the include/leveldb directory (header files) to my environment path.
My test code:
/*leveldb_test.cpp
*/
#include <iostream>
#include <sstream>
#include <string>
#include <leveldb/db.h>
using namespace std;
int main(int argc, char** argv)
{
leveldb::DB* db;
leveldb::Options options;
options.create_if_missing = true;
leveldb::Status status = leveldb::DB::Open(options, "./testdb", &db);
assert(status.ok());
return 0;
}
And I compile it as:
g++ leveldb_test.cpp -o leveldb_test -lpthread -lleveldb -std=c++11
It produces "undefined reference" errors:
leveldb_test.o: In function `main':
leveldb_test.cpp:(.text+0x79): undefined reference to `leveldb::DB::Open(leveldb::Options const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, leveldb::DB**)'
leveldb_test.cpp:(.text+0x29e): undefined reference to `leveldb::Status::ToString[abi:cxx11]() const'
collect2: error: ld returned 1 exit status
What is the problem?
My environment: Linux version 3.10.0-327.el7.x86_64 - gcc version 4.8.3 20140911 - Red Hat 4.8.3-9
Thanks for any advise.
Here is a simple C++ program and I believe it should work. My code is reference from here.
Convert command line argument to string
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <iostream>
//using namespace std;
int main(int argc, char *argv[]){
std::string boss;
//printf("PROGRAM NAME: %s\n", argv[0]);
if (argc > 1){
//printf("%s\n",&argv[1][0]);
printf("%s\n",argv[1]);
boss = argv[1];
}
}
When Compile it come out the problem:
/tmp/cctYLBpB.o: In function main':
testarg.cpp:(.text+0x1c): undefined reference tostd::basic_string, std::allocator >::basic_string()'
testarg.cpp:(.text+0x58): undefined reference to std::string::operator=(char const*)'
testarg.cpp:(.text+0x64): undefined reference tostd::basic_string, std::allocator >::~basic_string()'
testarg.cpp:(.text+0x78): undefined reference to std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
testarg.cpp:(.text+0x7c): undefined reference to__cxa_end_cleanup'
/tmp/cctYLBpB.o: In function __static_initialization_and_destruction_0(int, int)':
testarg.cpp:(.text+0xc0): undefined reference tostd::ios_base::Init::Init()'
testarg.cpp:(.text+0xe4): undefined reference to std::ios_base::Init::~Init()'
/tmp/cctYLBpB.o:(.ARM.extab+0x0): undefined reference to__gxx_personality_v0'
collect2: error: ld returned 1 exit status
Did you guys expert had seen any problem on it ? I have no idea ...
When you use gcc to build your program, the standard C++ libraries are not used by the linker. Use g++ instead. Add -Wall for good measure. You will get useful warning messages that will help you find problems at compile time rather than find them at run time.
g++ filename.cpp -Wall -o testc
i have the following code:
#include "Poco/Net/DatagramSocket.h"
#include "Poco/Net/SocketAddress.h"
#include "Poco/Timestamp.h"
#include "Poco/DateTimeFormatter.h"
int main(int argc, char** argv)
{
Poco::Net::SocketAddress sa("127.0.0.1", 8080);
Poco::Net::DatagramSocket dgs(sa);
std::string syslogMsg;
Poco::Timestamp now;
syslogMsg = Poco::DateTimeFormatter::format(now,
"<14>%w %f %H:%M:%S Hello, world!");
return 0;
}
and after compiling i get the following errors:
/tmp/cc38RdWw.o: In function `main':
pocoSender.cpp:(.text+0x4d): undefined reference to `Poco::Net::SocketAddress::SocketAddress(std::string const&, unsigned short)'
pocoSender.cpp:(.text+0x7d): undefined reference to `Poco::Net::DatagramSocket::DatagramSocket(Poco::Net::SocketAddress const&, bool)'
pocoSender.cpp:(.text+0x93): undefined reference to `Poco::Timestamp::Timestamp()'
pocoSender.cpp:(.text+0x11f): undefined reference to `Poco::Timestamp::~Timestamp()'
pocoSender.cpp:(.text+0x135): undefined reference to `Poco::Net::DatagramSocket::~DatagramSocket()'
pocoSender.cpp:(.text+0x140): undefined reference to `Poco::Net::SocketAddress::~SocketAddress()'
pocoSender.cpp:(.text+0x163): undefined reference to `Poco::Net::SocketAddress::~SocketAddress()'
pocoSender.cpp:(.text+0x1ac): undefined reference to `Poco::Timestamp::~Timestamp()'
pocoSender.cpp:(.text+0x1ca): undefined reference to `Poco::Net::DatagramSocket::~DatagramSocket()'
pocoSender.cpp:(.text+0x1d9): undefined reference to `Poco::Net::SocketAddress::~SocketAddress()'
/tmp/cc38RdWw.o: In function `Poco::DateTimeFormatter::format(Poco::Timestamp const&, std::string const&, int)':
pocoSender.cpp:(.text._ZN4Poco17DateTimeFormatter6formatERKNS_9TimestampERKSsi[_ZN4Poco17DateTimeFormatter6formatERKNS_9TimestampERKSsi]+0x15): undefined reference to `Poco::DateTime::DateTime(Poco::Timestamp const&)'
pocoSender.cpp:(.text._ZN4Poco17DateTimeFormatter6formatERKNS_9TimestampERKSsi[_ZN4Poco17DateTimeFormatter6formatERKNS_9TimestampERKSsi]+0x43): undefined reference to `Poco::DateTime::~DateTime()'
pocoSender.cpp:(.text._ZN4Poco17DateTimeFormatter6formatERKNS_9TimestampERKSsi[_ZN4Poco17DateTimeFormatter6formatERKNS_9TimestampERKSsi]+0x52): undefined reference to `Poco::DateTime::~DateTime()'
/tmp/cc38RdWw.o: In function `Poco::DateTimeFormatter::format(Poco::DateTime const&, std::string const&, int)':
pocoSender.cpp:(.text._ZN4Poco17DateTimeFormatter6formatERKNS_8DateTimeERKSsi[_ZN4Poco17DateTimeFormatter6formatERKNS_8DateTimeERKSsi]+0x41): undefined reference to `Poco::DateTimeFormatter::append(std::string&, Poco::DateTime const&, std::string const&, int)'
collect2: error: ld returned 1 exit status
i use the following commandline to compile:
g++ -L/usr/local/lib -lPocoUtil -lPocoFoundation -lPocoNet pocoSender.cpp -o hello
please do not mark the question as duplicate as i have included the required libraries using g++ flags, but i am still getting these errors.
It means that the compiler or linker did not find implementations of these functions. It seems that the corresponding libraries or object modules were not included in building of the project.