Google Test. Microsoft Visual Studio 2022. How to create different files with test in one Google test project? [closed] - googletest

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed yesterday.
Improve this question
I am using the latest version of MVS 2022. I have a solution with 2 projects. The second one is Google test project created from a template. I want to test the first one. In the first project I have a main.cpp, Sum.h, Sum.cpp. Sum.h has a simple declaration of function int Sum(int lhs, int rhs), Sum.cpp has it's defenition. In my Google test project i want to test function Sum(). I want to write different tests in different cpp files. In order to do it I need to include my Sum.h file either in pch.h file or in every test1.cpp, test2.cpp, .... file. Sum.h contains #pragma once.
Why when I include Sum.h file in pch.h i have an error: LNK2019, LNK1120 (smth like undefined ref to the element Sum(int, int))?
Why when I include Sum.h in both test1.cpp, test2.cpp file i receive a multiple defenition error.
How do I fix my problem?
Tried usin Microsoft Unit tests framework. The same problem.

Related

How do I enable LinkTimeOptimization with Clion? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'd like to have my program link time optimized. Where do I have to enter it to enable it?
If it matters (I hope it doesn't): I'm using MinGW-w64 5.0 on Windows.
edit: I really don't see why it wouldn't matter that I'm using CLion. I'm aware that - for now - it uses CMake as underlying build system.
But a) In the future CMake won't be the only build system that CLion will support (See here), so refering to CMake wouldn't solve the problem itself.
And b) adjusting the CMakeLists.txt would still require, that I configure each project individually. I asked for a way to configure the IDE, so it would do it for me.
I also don't this that it's an unsolvable problem per se. There could be a configuration or a PlugIn that does the trick. I failed to find it.. yet that doesn't mean that my question is unanswerable.
In general, this has nothing to do with CLion, but is a matter of CMake.
The problem, however, is that the appropriate flags differ among the compilers and linkers.
As you are using MinGW and, as far as I know that implies GCC, you can try the following as a rough starting point:
if(${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -flto")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} -flto")
set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} -flto")
endif()
However, I'd recommend using target properties (assuming you have a target MyTarget as an executable or shared library defined):
if(${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
set_property(TARGET MyTarget
APPEND PROPERTY LINK_FLAGS -lto)
endif()

OCR Framework that can read text from images in iOS?

I'm currently starting a project right. One of the requirements is to read details of a "Cheque" .Meaning to say, the app should be able to read the account number, amount, etc of a certain "Cheque".
There is a similar question here
I tried something ago and works fine. Check the open source project called tesseract and also a demonstration here (with source code)

Revert all files in a folder [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
Is there a way to revert all the documents in a folder to the revision at a certain time? I see how to do it for individual files, but how would I do it for an entire folder?
I had the same problem, so I wrote this script to restore any dropbox folder to its state as of a given date:
https://github.com/clark800/dropbox-restore
You have several options:
If you've recently done something that has modified a large bunch of files in your Dropbox and you want to revert all those changes, you can contact the support staff at Dropbox to have the modifications rolled back. See https://www.dropbox.com/help/400/en for details. Based on discussions in the Dropbox forums, it seems like they are also willing and able to restore any given folder to an arbitrary date, as long as it is within the bounds stored by Dropbox (30 days for a basic account; for accounts with the packrat feature all the way back to when packrat was activated).
You could use the script written by clark800, linked to in a separate answer to this question. I haven't used it so cannot vouch for it, but many seem very happy with it!
If you are on a Mac (OS X 10.7 or later), you can try out a new app called Revisions (available at https://www.revisionsapp.com) that I've been working on. The app allows you to select any folder in your Dropbox and shows you a timeline of all edits for that folder. Then, you can choose to restore or download any version of any single file, or restore or download an entire folder (including any subfolders) to its state at any desired point in time (subject to the Dropbox bounds stated above).
To my knowledge restoring to a particular revision is limited to a per file operation. It would be possible to accomplish what you are looking for using their REST API however it would require custom code.
If you don't want to use a script, Dropbox does allow you to select multiple files at the same time and restore them (if you login to your account online). Right click and select 'Show deleted files' first. Then if it's just a few folders, either select the files individually by holding down 'Ctrl' and selecting them, or using 'Ctrl' and 'A' to select them all. Then right click and select restore.

Linker chooses "wrong" main with Boost.Test

When using Boost.Test, there is generally no need to define a main() function, since Boost.Test provides one itself.
I recently had to convert my project to use static linking of 3rd party libraries (on VS2010). Naturally, I had to link to multiple .libs so that the build succeeds, and my build ran just fine.
However, when I ran my test project, something really strange happened. It seems that one of the 3rd party .libs (libpng), required by one of my dependent libraries, contained a test file with a main() function defined within (pngtest.c, if you must know).
Since my project did not have a main() function, the linker chose that one as my "test" application. Thus, non of my tests run.
Does anyone know how I prevent this from happening? How can I tell the linker/compiler to use the Boost.Test main()?
Answering my own question, and clarifying #Tom's answer.
Turns out that the libpng build script I was using was not the the original shipping with libpng but one created by the OpenCV build system. The file pngtest.c was mistakenly included int the build.
The solution to the problem was to remove pngtest.c from the libpng build script.
The latest OpenCV version, does not include this file anymore.
For more details see my post to Boost mailing list here and my OpenCV bug report here.
Adi, I had the same problem. Looks like you were already all over this one. Thanks to Google and your efforts, I was able to figure it out.
Here's some info to round out the answer:
discussion:
http://boost.2283326.n4.nabble.com/Boost-Test-Linker-chooses-wrong-main-function-td4634872.html
solution:
http://code.opencv.org/issues/2322
Basically, I just excluded the pngtest.c file from the libpng project, and recompiled OpenCV. Looks like it will be fixed in the next release of OpenCV.
Thanks!

Documenting C++/CLI library code for use from c# - best tools and practices? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I'm working on a project where a c++/cli library is being used primarily from a c# application.
Is there any way to make the code comments in c++/cli visible to c# intellisence within visual studio?
Assuming there isn't, what would be the best way to document the c++/cli code to enable its easier use from c# (and within c++/cli of course)? What is you opinion on XML comments vs doxygen vs other tools (which)?
I have gotten it to work as follows:
Use XML style comments for your C++/CLI header entries. This means the full XML comment is required (triple-slash comments, <summary> tag at a minimum)
Make sure that the C++ compiler option Generate XML Documentation Files is on. This should generate an XML file with documentation with the same name as your assembly (MyDll.xml).
Make sure that the C# project references your assembly MyDll.dll where MyDll.xml is also present in the same folder. When you mouse over a reference from the assembly, MS Visual Studio will load the documentation.
This worked for me in Visual Studio 2008 on an assembly built for .NET 3.5.
DocXml has the major advantage of being supported by VS (syntax colouring, intellisense, automatic export to the XML files). The Doxygen tools can read DocXml format so you can still use them with this format too.
To help you generate tidy and accurate Doc comments with a minimum of effort, you might like to check out my addin AtomineerUtils. This takes most of the work out of creating and updating DocXml, Doxygen, JavaDoc or Qt format comments, and it supports C, C++, C++/CLI, C#, Java, JavaScript, TypeScript, JScript, UnrealScript, PHP and Visual Basic code.
Interesting. After trying several methods, it's looking like the intellisense between a Managed C++ project and C# doesn't work.
The following example will give you proper intellisense in the C++ environment where it is declared, but referencing the object in C# shows nothing:
// Gets the value of my ID for the object, which is always 14.
public: virtual property int MyId
{
int get() { return 14; }
}
XML comments don't work either. I would guess that this is either a bug, or requires something I can't figure out. Judging from the lack of answers on this question, perhaps a bug.
As far as documentation generation, I'd recommend going the path of XML documentation. Doxygen supports reading XML documentation which is mostly identical to the standard XML documentation for C#. It does tend to add extra lines just for tag openings and closings, but is much more readable in my opinion than the following doxygen alternative:
//! A normal member taking two arguments and returning an integer value.
/*!
\param a an integer argument.
\param s a constant character pointer.
\return The test results
\sa Test(), ~Test(), testMeToo() and publicVar()
*/
You are right. It doesn't work. The C++ build will add its IntelliSense information into the master .ncb file, and you will get the autocompletion of method names, etc. However, you are correct in that you will be unable to get the "comment" description about each method, etc.
You'll probably have a lot of value taking a look at Doxygen. And then look up Doxygen.NET - which is something we wrote for our own use which builds "Object Hierarchies" from the XML file outputs from Doxygen...