I am relatively new to C++ and I am using CLions. I am trying to run this code as follows:
/*
* File: Warmup.cpp
* ----------------
#include <iostream>
#include <string>
#include "../lib/StanfordCPPLib/console.h"
#include "../lib/StanfordCPPLib/simpio.h"
using namespace std;
/* Constants */
const int HASH_SEED = 5381; /* Starting point for first cycle */
const int HASH_MULTIPLIER = 33; /* Multiplier for each cycle */
const int HASH_MASK = unsigned(-1) >> 1; /* All 1 bits except the sign */
/* Function prototypes */
int hashCode(string key);
/* Main program to test the hash function */
int main() {
string name = getLine("Please enter your name: John");
int code = hashCode(name);
cout << "The hash code for your name is " << code << "." << endl;
return 0;
}
/*
* Function: hash
* Usage: int code = hashCode(key);
* --------------------------------
int hashCode(string str) {
unsigned hash = HASH_SEED;
int nchars = str.length();
for (int i = 0; i < nchars; i++) {
hash = HASH_MULTIPLIER * hash + str[i];
}
return (hash & HASH_MASK);
}
However, I am getting the following errors:
[ 50%] Building CXX object CMakeFiles/Warmup.dir/src/Warmup.cpp.o [100%] Linking CXX executable Warmup ld: library not found for -llib/StanfordCPPLib clang: error: linker command failed with exit code 1 (use -v to see invocation) make[3]: * [Warmup] Error 1 make[2]: [CMakeFiles/Warmup.dir/all] Error 2 make[1]: [CMakeFiles/Warmup.dir/rule] Error 2 make: * [Warmup] Error 2
I know that this works for microsoft studio C++ but I am not sure why it isnt running for CLions. Would someone mind giving some advice here ?
Any help would be greatly appreciated.
Thanks
Edit: This is what my current CMakeLists.txt file looks like:
cmake_minimum_required(VERSION 3.6)
project(0_Warmup)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILE src/Warmup.cpp)
link_libraries(lib/StanfordCPPLib)
add_executable(Warmup src/Warmup.cpp)
Am I making an error linking this library somewhere ?
lib/StanfordCPPLiband it cannot be found. is it in the appropriate folder? - Hayt-L<path>option. - πάντα ῥεῖlink_libraries(lib/StanfordCPPLib). I also have it in folder stored as lib/StanfordCPPLib where I marked the lib folder as a library root because the compiler does not allow me to import the needed header files when I simply mark StanfordCPPLib as a library root. - PutsandCalls