简体   繁体   中英

Problems creating a static C++ library

Greetings fellow programmers! I am trying to create a C++ library to use in other projects. This library is to be a static library that will be linked to other projects.

Problem: The compiler doesn't seem to catch errors that it otherwise would if it were configured as an executable program under Project->Properties>General. In fact I purposely made a syntax error and the compiler gave me a success regardless.

Is there a way to force the compiler to check everything while building a static lib?

Build Environment: Visual Studio 2010

EDIT: As it turns out, it was a rather simple, yet incredibly subtle mistake. It turns out that Visual studio was treating some of my .cpp files as header files. Because of this, the compiler was not running through the code at all (no one includes .cpp files). When adding files to the library, I must have accidentally selected header instead of C++ file. I thought Visual Studio would only rename the header file. I guess I was wrong!

This is nonsensical. It cannot happen. What is probably happening is that you think that the compiler is compiling your source file, (the one with the syntax error,) but it does not. Perhaps you have not added your source file to your project.

(Then again, C++ has a pretty quirky syntax; I hope you are sure that what you made was in fact a syntax error, and not a syntactically valid language construct.)

如果在工作区(解决方案)中有多个项目(如exe和lib),请确保单击要构建的项目或将其设置为启动项目(以粗体字母显示),如果按F7按钮。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM