New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Undefined reference to `hmdf::HeteroVector::clear()' #56
Comments
You are getting this error because you are not linking with the DataFrame library. If you follow the build instructions with |
Thank you for your reply. I followed the instructions for installing the library using cmake, and it now appears that I was successful in installing the library. However, I'm still getting the undefined reference errors when I try to compile the .cpp file using g++. For the purpose of just getting this very trivial program to compile and successfully instantiate the StdDataFrame (and thus passing the smoke test), is there a specific change that I should be making to the libraries that I am #including or to the arguments I'm passing to g++ in the Bash terminal? |
There is nothing wrong with your
That is a typical command line to compile and link any C++ program using a library, whether it is a very simple program or very complicated. Hope that helps |
It works! Thank you! |
I'm sorry to bother you with this again, but I'm getting error messages again when I try to compile from multiple source files (and use header files) and then link the objects together into an executable. Is the problem the Makefile, the .cpp files, or the header file? And shouldn't the #pragma once directive prevent the read_data.h file, as well as the library headers, from being read multiple times which is what leads to multiple reference errors? I've tried making multiple changes to the #include directives in the .cpp files and the header files and nothing seems to have worked. What am I missing here? main.cpp.txt |
I can see a few problems, but you may have more.
It is hard to debug remotely. |
I accidentally posted a later iteration of what I was working with after a series of trial-and-error attempts, and I apologize for loading the wrong file there. I corrected the problems you mentioned, but I'm still getting errors and I'm not sure why this keeps happening. I understand that the C/C++ compiling process consists of: preprocessing, where the compiler follows preprocessing directives such as expanding macros and including libraries and header files; compiling the C/C++ files (while following preprocessing directives) into assembly language code; assembling the assembly language code into binary object files; and linking the binary object files into a binary executable that contains direct instructions that the computer can then execute. The Makefile contains a series of instructions to the compiler so that for a large program whose source code is spread across (for example) 20 files, the programmer does not have to manually type 20 different instructions into the shell to create the object files before linking them together into the binary executable. So far the only way that I have stopped getting errors has been to #include read_data.cpp from the main.cpp file, but I know that this is a sloppy kludge and considered very bad style; I also know that such a "solution" will break as soon as I add more .cpp files. What I'm having trouble understanding now, after having applied the changes, is why I'm getting a multiple definition error for hmdf::gen_bernoulli_dist() when 1) the #include directive to use the library file containing it exists only in the read_data.h file and nowhere else and 2) the header file read_data.h has a #pragma once directive. I'm also not sure why there is an undefined reference error for hmdf::HeteroVector::HeteroVector() when the header file has an explicit #include <DataFrame/Vectors/HeteroVector.h> directive on Line 16. What did I enter incorrectly for the DataFrame library location? I thought the Makefile was pointing to the location where it's installed. Any help you could provide here would be much appreciated. Not being able to compile the code due to these errors seems to be the main bottleneck in my project. main.cpp.txt |
Your understanding of the compile process is incorrect. Also, your understanding of what role header files play is incorrect. I still suggest you put some time aside to read up on them. I still see problems:
This is a typical line for compiling an object file
And this is a typical line to link an executable
|
Thank you. I will try to implement your suggestions. If I followed your installation instructions correctly, where should the library be located on a Linux machine? |
CMake decides dynamically. But I imagine in your system it would somewhere under |
Just to clarify, is the issue now solely the Makefile, or are there still problems with the .cpp files and the read_data.h header file? |
From my cursory look, there is nothing wrong in the source code |
Thank you. This clarification will save me a lot of time! |
i'm compiling under MSVC 2022 with DataFrame.lib (i got it via vcpkg) but it gives me "Undefined reference to `hmdf::HeteroVector::clear()" error |
Most probably because when you are linking your executable, you are not linking with the DataFrame library |
other than DataFrame.lib? |
there must be something wrong with vcpkg, i built everything from github repo and now it works fine |
When I tried to smoke test my code, I found that even trying to declare a dataframe resulted in an error at compile time. Am I missing a header file?
I'm running Debian 10 and am not using an IDE - I'm simply using g++ (I will create a Makefile once my code makes it past the smoke test). Below is the command I am using and the corresponding error.
username@system:/tmp/smoke_test$ g++ test_dataframe.cpp -I DataFrame/include/ -std=gnu++17 -o test_dataframe
/usr/bin/ld: /tmp/ccjU2Oy0.o: in function
hmdf::HeteroVector::~HeteroVector()': test_dataframe.cpp:(.text._ZN4hmdf12HeteroVectorD2Ev[_ZN4hmdf12HeteroVectorD5Ev]+0x14): undefined reference to
hmdf::HeteroVector::clear()'collect2: error: ld returned 1 exit status
test_dataframe.cpp.txt
The text was updated successfully, but these errors were encountered: