Sign in to follow this  
maxest

[Visual Studio] Use recompiled without recompiling the whole project using it

Recommended Posts

maxest    623
I know I'm in bad subforum but couldn't find any more suitable. So, I'm writing a simple static library. I'm also writing an application that uses this library. I modify lib's and app's code all the time. The problem is that if I want to have an always updated lib used in the application, I need to recompile the whole application. I don't quite understand this. If lib is recompiled, why then doesn't the application use it, but uses some old "version"? I really don't want to recompile the whole application after every single change in lib's code. What can I do to speedup my development process? :)

Share this post


Link to post
Share on other sites
xDS4Lx    126
I am going to assume you have the lib and the project using it in one solution in studio. You have to recompile the entire application using the library because it is a static library which means that when linking to it code is brought into your executable from the library so you don't have to include it like a dll, which means any changes to the library force the application using it to recompile. Want to avoid this, then change the lib project to a dll.

Share this post


Link to post
Share on other sites
jpetrie    13159
A static library is linked in to the executable at build time. If the library changes, the application must thus be relinked. If part of the code changes to the library included changes to any headers that the application's source files include, those source files will rebuild as well. This is just how C++'s compilation model works.

Moving to General Programming.

Share this post


Link to post
Share on other sites
maxest    623
Quote:

If the library changes, the application must thus be relinked.

Mhm, it's first time for me to play with static libraries and I had missed Build -> Project Only -> Link Only option before :). So I don't really have to recompile the project, just relink it. However, let's say I'm linking with 100 libs (it's hypothetical situation) and that I would like to relink only one of them. Is sort of things like this possible?
I'm just considering improving my prodictivity when handling applications and libs separately :).

Share this post


Link to post
Share on other sites
jpetrie    13159
Quote:

Mhm, it's first time for me to play with static libraries and I had missed Build -> Project Only -> Link Only option before :).

If you do this, and you have changed headers from the library, you will likely experience strange and interesting bugs and crashes.

Quote:

However, let's say I'm linking with 100 libs (it's hypothetical situation) and that I would like to relink only one of them. Is sort of things like this possible?

Yes, but...

Quote:

I'm just considering improving my prodictivity when handling applications and libs separately :).

...in general it is best to just let the build system do its work. It's doing what it needs to do.

Share this post


Link to post
Share on other sites
maxest    623
Hmmm... if rebuilding is the best way then it's quite a "slow" solution to the problem. Let's consider two cases:

1. Lib has 100 files, app has 100 files. I changed something in lib file - I recompile this one file within the lib. Now I need to recompile the whole application (100 files) just becuase I had recompiled one file from the lib ?(!)
2. Lib and app are merged - one project containing 200 files. Change in one cpp file from the "lib" doesn't involve recompiling the app ("it's" 100 files)

Note that I'm mostly talking about modifying lib's cpp files, not headers. It's clear that when I modify headers I need to recompile the app's cpp files that are including this header. But when I make changes in lib's cpp files then I only need to relink app with that lib, right?

Share this post


Link to post
Share on other sites
Antheus    2409
Quote:
Original post by maxest

1. Lib has 100 files, app has 100 files. I changed something in lib file - I recompile this one file within the lib. Now I need to recompile the whole application (100 files) just becuase I had recompiled one file from the lib ?(!)
2. Lib and app are merged - one project containing 200 files. Change in one cpp file from the "lib" doesn't involve recompiling the app ("it's" 100 files)


Static libs don't change. They are a distribution mechanism, a bundle. Typical environment will use a versioned lib against which everyone else developers. Upgrading this version is A Big Thing(tm).

Upgrading versions might be a part of nightly or weekly build. At least for projects of such scale.

If changing stuff, working with libs doesn't help. Libs are for stuff that does not change.

Quote:
But when I make changes in lib's cpp files then I only need to relink app with that lib, right?

Lots of stuff, especially since compilers these days do link-time optimization.

Naive linker would just put stuff together, but it still needs to do a lot of work across entire result to mangle the symbols. It has a lot to do with how executable images are laid out and how the code is interconnected, the memory model, segments, etc... But if one symbol increases in size by one byte, it can cause possibly require all addresses across entire executable to change.

Related reading: Courgette algorithm.


In theory, a special version of compiler could indeed just replace a symbol, and patch what is needed. But since linker is a standalone process, all information that would be needed (we're talking potentially gigabytes here) is discarded each time linker process exits.

Share this post


Link to post
Share on other sites
maxest    623
Let's get this staight. If I really need to recompile the whole project after making changes in the lib, then does it make sense to develop the library separately? Maybe this would really be better to merge the app and the lib and have this 200 files in one project. This would be much more effective.
But how then professional projects handle this? They must be using some additional test applications to test the lib they are developing (and constantly changing). How do they manage the development process?

Share this post


Link to post
Share on other sites
Plerion    381
To be honest: Where is the problem about recompiling/linking? If i change a .cpp in one of my projects static libraries and recompiling the solution the linking and codegeneration process takes 1-2 minutes. And most of my projects are a lot bigger than 100 files in lib and 100 files in the project. So there aint a problem with the time.

Share this post


Link to post
Share on other sites
Antheus    2409
Quote:
Original post by maxest

But how then professional projects handle this? They must be using some additional test applications to test the lib they are developing (and constantly changing). How do they manage the development process?


Usually, each team will be working on its own part. They will depend on other libraries, but specific version of them. Periodically, as teams progress, they will release a new version. Time is then allocated to integrate and test the new version, submit patches, etc.

However, this applies to the case mentioned above - hundreds of libs (aka, 1MLOC+ project, 50-500 developers, release schedules, planning and architecture). The API must be nailed pretty accurately from the beginning, since everyone else will be depending on it. Development is plannet, either in sprints or via other methods, changes are published once every few weeks, perhaps even months, libraries are released at a certain specific schedule - this allows everyone else who depends on it to plan in advance for integration problems. "always changing" argument no longer applies.


A lib should encompass self-contained functionality. SDL, OGL, ... Something rounded and well defined. Each such lib then comes with battery of standalone tests that are ran in isolation.


Unless you have plans to release the library as a standalone, then they aren't really needed, should be part of automated build infrastructure (cluster/nightly build), or should not be modified.

Share this post


Link to post
Share on other sites
Hodgman    51336
Quote:
Original post by maxest
1. Lib has 100 files, app has 100 files. I changed something in lib file - I recompile this one file within the lib. Now I need to recompile the whole application (100 files) just becuase I had recompiled one file from the lib ?(!)
Wait... what?
That shouldn't happen. If the lib changes, there's no reason that all 100 of the app's source files should have to be recompiled.
All that should have to happen is that the app is re-linked (without re-compiling anything).

Are you sure you're not editing a lib-header which is included by all the app-source files?

Share this post


Link to post
Share on other sites
maxest    623
I think I'm gettin this, but let me reformulate the problem again and consider it.
I have my gaming engine and I want to develop the application based on it. So I want the engine to be a separate project that produces lib and I want the game to use that lib. However, I would be modyfing the engine and game constantly. In this case it simply doesn't seem to pay off have the engine as separate lib, because every single change in engine's source will entail recompilation of game code. So in that case it's simply better to have engine and game in one project, right?

EDIT:
Quote:

Wait... what?
That shouldn't happen. If the lib changes, there's no reason that all 100 of the app's source files should have to be recompiled.
All that should have to happen is that the app is re-linked (without re-compiling anything).

Are you sure you're not editing a lib-header which is included by all the app-source files?

At the time I'm not editing anything, these are all considerations here before I reorganize my project ;)

So you say that after change in lib's SOURCE file I only need to relink the application? And after modyfing header file I need to recompile app's sources that use that modifed header and relink app with the lib?

Share this post


Link to post
Share on other sites
Hodgman    51336
Quote:
Original post by maxest
However, I would be modyfing the engine and game constantly. In this case it simply doesn't seem to pay off have the engine as separate lib, because every single change in engine's source will entail recompilation of game code. So in that case it's simply better to have engine and game in one project, right?
In my project, the engine is made up of about 9 libs, and the app as 1 lib and 1 exe.
I'm constantly editing all of these libs -- when I do that, I don't have to recompile anything (I just have to re-link the exe)!
[edit]
Quote:
So you say that after change in lib's SOURCE file I only need to relink the application? And after modyfing header file I need to recompile app's sources that use that modifed header and relink app with the lib?
Yes. Furthermore the IDE does this for you (figures out which files need to be relinked/recompiled, so you don't have to any of it manually).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this