Why can't I call an assembly program from C++? I'm getting errors.

I’m not sure which compiler/assembler you’re using, so I can’t comment on the assembly code itself. However, you will need to enable the ASM language in your project:

cmake_minimum_required(VERSION 3.11)
project(discourse709 LANGUAGES CXX ASM)  # ASM must be last

add_executable(test test.cpp test.s)

If you’re using the GNU assembler (GAS), then the following files work for test.cpp and test.s:

test.cpp
#include <iostream>

extern "C" int my_asm_fun();

int main() {
    int value = my_asm_fun();
    std::cout << "value = " << value << "\n";
    return 0;
}
test.s
    .globl my_asm_fun

    .text
my_asm_fun:
    mov $42, %rax
    ret