编译代码时出错,链接器命令失败

Error when compiling the code, linker command failed?

本文关键字:命令 失败 链接 代码 出错 编译      更新时间:2023-10-16

我对c++比较陌生,我正在使用CLions。我正试图按如下方式运行这段代码:

/*
 * 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);
}

但是,我得到以下错误:

[50%]构建CXX对象CMakeFiles/warm .dir/src/warm . cppo[100%]链接CXX可执行预热程序:没有找到库-llib/StanfordCPPLib clang: error: link command failed with exit code 1(使用-v查看调用)make[3]: * [Warmup] error 1make[2]: [CMakeFiles/预热。错误2 make[1]: [CMakeFiles/热身。错误2:*[热身]错误2

我知道这适用于microsoft studio c++,但我不确定为什么它不能在CLions上运行。有人能给点建议吗?

任何帮助都将非常感激。

感谢

编辑:这是我当前的CMakeLists.txt文件的样子:

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)

链接这个库时出错了吗?

我认为你在上面添加了//

#include "../lib/StanfordCPPLib/console.h"
#include "../lib/StanfordCPPLib/simpio.h"// library and u shud try once again a right path of library folder ..
相关文章: