Closed RobertBernstein closed 11 months ago
Looks like you have 2 main functions. One via #define CATCH_CONFIG_MAIN
(this is the one you want). and an empty one that does nothing that you define yourself (this one is blocking/masking the one you need). I expect that if you delete the one you defined yourself everything should work.
I thought that might be the problem, but when I delete it I get a linker error. I'm not at the computer right now, but it's telling me that my project has no main function. I even tried telling it I don't need a main function in the Advanced linker settings, but got an error that this setting can only be used for DLLs. Any idea how to eliminate the linker error?
When I remove the main
method that I added, the error I'm getting is:
1>------ Rebuild All started: Project: Catch2Test, Configuration: Debug x64 ------
1>Catch2Test.cpp
1>MSVCRTD.lib(exe_main.obj) : error LNK2019: unresolved external symbol main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)
1>D:\Dev\GitHub\RobertBernstein\Catch2Test\x64\Debug\Catch2Test.exe : fatal error LNK1120: 1 unresolved externals
1>Done building project "Catch2Test.vcxproj" -- FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
========== Rebuild started at 8:05 PM and took 01.607 seconds ==========
This is not a problem with the test adapter so I'm closing this issue.
That being said, I did a quick search and the following stackoverflow question may give you a hint on what the problem may be and how to solve it: Error LNK2019 unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)"
@JohnnyHendriks: I finally figured it out. I included #include <catch.hpp>
, but I did not add Catch2Main.lib
to my Release build Additional Dependencies and Catch2Maind.lib
to my Debug build Additional Dependencies in my Visual Studio C++ project. Now it works. I guess I took the whole "it's a header-only" library too literally.
I have tried a number of solutions to my problem (including from StackOverflow and other closed issues here) and would really appreciate some help getting the Catch2 VS Test Adapter to discover tests in my solution/project. I am using .vcxproj and .sln files, not CMake. I have done the following:
I still have no tests discovered in my Catch2Test.exe file. How do I fix this?
At one point, I included
std::cout << Factorial(6) << '\n';
in mymain
method and I saw720
in the output from the test adapter discovery process, which was weird.This is the entire
Catch2Test.cpp
file:and this is the entire Minimal.runsettings file:
I get the following output: