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
Related
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
This question already has answers here:
G++ Undefined Reference std::
(2 answers)
Closed 2 years ago.
I have a simple bit of code which is having trouble compiling.
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char **argv) {
string hello = "Hello World";
printf("%s\n",hello.c_str());
return 0;
}
compiling with "gcc test.cpp -o test"
returns the following message.
/tmp/ccgbRaOf.o: In function main':
test.cpp:(.text+0x27): undefined reference tostd::allocator::allocator()'
test.cpp:(.text+0x3e): undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
test.cpp:(.text+0x4a): undefined reference tostd::allocator::~allocator()'
test.cpp:(.text+0x56): undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::c_str() const'
test.cpp:(.text+0x6a): undefined reference tostd::__cxx11::basic_string, std::allocator >::~basic_string()'
test.cpp:(.text+0x8f): undefined reference to std::allocator<char>::~allocator()'
test.cpp:(.text+0xa9): undefined reference tostd::__cxx11::basic_string, std::allocator >::~basic_string()'
/tmp/ccgbRaOf.o: In function __static_initialization_and_destruction_0(int, int)':
test.cpp:(.text+0xe9): undefined reference tostd::ios_base::Init::Init()'
test.cpp:(.text+0xfe): undefined reference to std::ios_base::Init::~Init()'
/tmp/ccgbRaOf.o:(.data.rel.local.DW.ref.__gxx_personality_v0[DW.ref.__gxx_personality_v0]+0x0): undefined reference to__gxx_personality_v0'
collect2: error: ld returned 1 exit status
What am I doing wrong?
You compile it with gcc which is for C, but your code is C++. Use g++.
It does not work because you are using a C compiler. For C++ you need a different compiler. Try with g++
I want to compile the following code with mingw-w64.
#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
Mat im = imread("lena.jpg", 1);
if (im.empty())
{
cout << "Cannot open image!" << endl;
return -1;
}
imshow("image", im);
waitKey(0);
return 0;
}
after following Getting started with OpenCV 2.4 and MinGW on Windows 7
I compile the code with g++ -I D:\opencv\build\include -L D:\opencv\build\x64\vc14\lib -lopencv_world310 .\loadimg.cpp
but it returns undefined reference
C:\Users\1409021\AppData\Local\Temp\cc8ZRPJP.o:loadimg.cpp:(.text+0x40): undefined reference to `cv::imread(cv::String const&, int)'
C:\Users\1409021\AppData\Local\Temp\cc8ZRPJP.o:loadimg.cpp:(.text+0xb7): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
C:\Users\1409021\AppData\Local\Temp\cc8ZRPJP.o:loadimg.cpp:(.text+0xd9): undefined reference to `cv::waitKey(int)'
C:\Users\1409021\AppData\Local\Temp\cc8ZRPJP.o:loadimg.cpp:(.text$_ZN2cv6StringC1EPKc[_ZN2cv6StringC1EPKc]+0x4a): undefined reference to `cv::String::allocate(unsigned long long)'
C:\Users\1409021\AppData\Local\Temp\cc8ZRPJP.o:loadimg.cpp:(.text$_ZN2cv6StringD1Ev[_ZN2cv6StringD1Ev]+0x11): undefined reference to `cv::String::deallocate()'
C:\Users\1409021\AppData\Local\Temp\cc8ZRPJP.o:loadimg.cpp:(.text$_ZN2cv3MatD1Ev[_ZN2cv3MatD1Ev]+0x36): undefined reference to `cv::fastFree(void*)'
C:\Users\1409021\AppData\Local\Temp\cc8ZRPJP.o:loadimg.cpp:(.text$_ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x48): undefined reference to `cv::Mat::deallocate()'
the library is opencv3.1, and there is only one library opencv_world310
Any advise?
Thank you.
g++ -I D:\opencv\build\include -L D:\opencv\build\x64\vc14\lib -lopencv_world310 .\loadimg.cpp
is wrong.
g++ -I D:\opencv\build\include -L D:\opencv\build\x64\vc14\lib .\loadimg.cpp -lopencv_world310
is right. Explained here
I'm trying to test a motor control lib I've wrote with googletest but I'm not been to compile the test's codes.
The test are in a file named test.cpp such as the following:
#include <gtest/gtest.h>
#include "../motor.hpp"
TEST(constructorTest, contructorDefault)
{
}
And I've put a the tests main function in an other file named main.cpp.
#include <gtest/gtest.h>
#include "../motor.hpp"
int main(int argc, char* argv[])
{
::testing::InitGoogleTest(&argc,argv);
RUN_ALL_TESTS();
}
To compile I've excecuted the following line:
g++ main.cpp test.cpp ../motor.cpp -o test
The result I get is:
main.cpp:8:17: warning: ignoring return value of ‘int RUN_ALL_TESTS()’, declared with attribute warn_unused_result [-Wunused-result]
RUN_ALL_TESTS();
^
/tmp/ccZ5BaBH.o: In function `main':
main.cpp:(.text+0x1e): undefined reference to `testing::InitGoogleTest(int*, char**)'
/tmp/ccZ5BaBH.o: In function `RUN_ALL_TESTS()':
main.cpp:(.text._Z13RUN_ALL_TESTSv[_Z13RUN_ALL_TESTSv]+0x5): undefined reference to `testing::UnitTest::GetInstance()'
main.cpp:(.text._Z13RUN_ALL_TESTSv[_Z13RUN_ALL_TESTSv]+0xd): undefined reference to `testing::UnitTest::Run()'
/tmp/ccFuAMp3.o: In function `__static_initialization_and_destruction_0(int, int)':
test.cpp:(.text+0x5c): undefined reference to `testing::internal::GetTestTypeId()'
test.cpp:(.text+0x84): undefined reference to `testing::internal::MakeAndRegisterTestInfo(char const*, char const*, char const*, char const*, void const*, void (*)(), void (*)(), testing::internal::TestFactoryBase*)'
/tmp/ccFuAMp3.o: In function `constructorTest_contructorDefault_Test::constructorTest_contructorDefault_Test()':
test.cpp:(.text._ZN38constructorTest_contructorDefault_TestC2Ev[_ZN38constructorTest_contructorDefault_TestC5Ev]+0x14): undefined reference to `testing::Test::Test()'
/tmp/ccFuAMp3.o:(.rodata._ZTV38constructorTest_contructorDefault_Test[_ZTV38constructorTest_contructorDefault_Test]+0x20): undefined reference to `testing::Test::SetUp()'
/tmp/ccFuAMp3.o:(.rodata._ZTV38constructorTest_contructorDefault_Test[_ZTV38constructorTest_contructorDefault_Test]+0x28): undefined reference to `testing::Test::TearDown()'
/tmp/ccFuAMp3.o: In function `constructorTest_contructorDefault_Test::~constructorTest_contructorDefault_Test()':
test.cpp:(.text._ZN38constructorTest_contructorDefault_TestD2Ev[_ZN38constructorTest_contructorDefault_TestD5Ev]+0x1f): undefined reference to `testing::Test::~Test()'
/tmp/ccFuAMp3.o:(.rodata._ZTI38constructorTest_contructorDefault_Test[_ZTI38constructorTest_contructorDefault_Test]+0x10): undefined reference to `typeinfo for testing::Test'
collect2: error: ld returned 1 exit status
If I remove the test.cpp of the compiling line I get this other result:
main.cpp: In function ‘int main(int, char**)’:
main.cpp:8:17: warning: ignoring return value of ‘int RUN_ALL_TESTS()’, declared with attribute warn_unused_result [-Wunused-result]
RUN_ALL_TESTS();
^
/tmp/cc61r6NU.o: In function `main':
main.cpp:(.text+0x1e): undefined reference to `testing::InitGoogleTest(int*, char**)'
/tmp/cc61r6NU.o: In function `RUN_ALL_TESTS()':
main.cpp:(.text._Z13RUN_ALL_TESTSv[_Z13RUN_ALL_TESTSv]+0x5): undefined reference to `testing::UnitTest::GetInstance()'
main.cpp:(.text._Z13RUN_ALL_TESTSv[_Z13RUN_ALL_TESTSv]+0xd): undefined reference to `testing::UnitTest::Run()'
collect2: error: ld returned 1 exit status
What am I doing wrong?
EDIT
Look like What #RippeR says is right, but now I getting the following error:
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../lib/libgtest.so: undefined reference to `pthread_key_create'
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../lib/libgtest.so: undefined reference to `pthread_getspecific'
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../lib/libgtest.so: undefined reference to `pthread_key_delete'
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../lib/libgtest.so: undefined reference to `pthread_setspecific'
Do I have to include something else?
Solution
The problem was solve adding the -lpthread flag to compile the test.
Try:
g++ main.cpp test.cpp ../motor.cpp -o test -lgtest -lpthread
You have to link external libraries you are using. Including headers is not enough (unless library is header-only). If this solutions doesn't work, or you get error about gcc cannot find lgtest or gtest then you need to install it first (see here).
Also, note that RUN_ALL_TESTS(); returns a value, so your main() should look like:
#include <gtest/gtest.h>
#include "../motor.hpp"
int main(int argc, char* argv[])
{
::testing::InitGoogleTest(&argc,argv);
return RUN_ALL_TESTS();
}
I've updated answer (check 2nd line) to cover your next problem. This is same as before, you really should start to FIND answers to your problems instead of just asking and waiting for someone to do all the work for you.
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.