I am making an implementation of ChaCha20. When compiling my code using g++
I get the "undefined reference to" error.
My main.cpp file.
#include <iostream>#include "chacha.h"Chacha20 cipher;int main() { uint32_t test_vector[4] = {0x11111111, 0x01020304, 0x9b8d6f43, 0x01234567}; cipher.quarter_round(test_vector); return 0;}
My chacha.h file.
#include <cstdint>class Chacha20 { public: void quarter_round(uint32_t *arr); private: uint32_t key[4]; uint32_t chacha_state[16];};
My chacha.cpp file.
#include <cstdint>class Chacha20 { public: void quarter_round(uint32_t *arr) { } private: uint32_t key[4]; uint32_t chacha_state[16];};
Running g++ main.cpp chacha.cpp chacha.h
returns the following error.
/usr/bin/ld: /tmp/ccoCsegN.o: in function `main':main.cpp:(.text+0x36): undefined reference to `Chacha20::quarter_round(unsigned int*)'collect2: error: ld returned 1 exit statuszsh: exit 1 g++ main.cpp chacha.cpp chacha.h