0

I am not being able to compile the following project.

The main.cpp is not being able to obtain trim() from the string_utils.hh.

string_utils.hh

#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <sstream>

#ifndef UTILS_STRING_UTILS_H
#define UTILS_STRING_UTILS_H

namespace utils
{
    std::string& trim(std::string& str, const std::string& delim = " \n\t\r");    
}

#endif

string_utils.cc

#include <cmath>
#include <string>

#include "string_utils.hh"

namespace utils
{
    std::string& trim(std::string& str, const std::string& delim)
    {
        return str;
    }
}

main.cpp

#include <iostream>
#include "string_utils.hh"

int main()
{
    std::string source_string = " Hello  World! ";

    std::cout << source_string << std::endl;

    std::string destination_2 = utils::trim(source_string, " ");    

    return 0;
}

CMakeList.txt

cmake_minimum_required (VERSION 3.8)

project ("string_utils__debugging__stripped__more")

add_executable (string_utils__debugging__stripped__more "main.cpp" )

Error

>------ Rebuild All started: Project: string_utils__debugging__stripped__more, Configuration: Mingw64-Debug ------
  [1/1] Cleaning all built files...
  Cleaning... 0 files.
  [1/2] C:\PROGRA~1\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\g++.exe   -g -MD -MT CMakeFiles/string_utils__debugging__stripped__more.dir/main.cpp.obj -MF CMakeFiles\string_utils__debugging__stripped__more.dir\main.cpp.obj.d -o CMakeFiles/string_utils__debugging__stripped__more.dir/main.cpp.obj -c ../../../main.cpp
  [2/2] cmd.exe /C "cd . && C:\PROGRA~1\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\g++.exe -g  CMakeFiles/string_utils__debugging__stripped__more.dir/main.cpp.obj -o string_utils__debugging__stripped__more.exe -Wl,--out-implib,libstring_utils__debugging__stripped__more.dll.a -Wl,--major-image-version,0,--minor-image-version,0  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
  FAILED: string_utils__debugging__stripped__more.exe 
  cmd.exe /C "cd . && C:\PROGRA~1\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\g++.exe -g  CMakeFiles/string_utils__debugging__stripped__more.dir/main.cpp.obj -o string_utils__debugging__stripped__more.exe -Wl,--out-implib,libstring_utils__debugging__stripped__more.dll.a -Wl,--major-image-version,0,--minor-image-version,0  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
  CMakeFiles/string_utils__debugging__stripped__more.dir/main.cpp.obj: In function `main':
  C:\Users\pc\source\repos\string_utils__debugging__stripped__more\out\build\Mingw64-Debug/../../../main.cpp:10: undefined reference to `utils::trim(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
C:\Users\pc\source\repos\string_utils__debugging__stripped__more\out\build\Mingw64-Debug\collect2.exe : error : ld returned 1 exit status
  ninja: build stopped: subcommand failed.

Rebuild All failed.

There is no template involved here. So, what is the issue?

user366312
  • 16,949
  • 65
  • 235
  • 452

0 Answers0