سؤال

I have a C project in visual studio that is named "Framework".

The Framework project is supposed to hold common code that should be shared among different projects.

I also have another project (Lets call it A) that should use code from the Framework.

Lets say the Framework project has a header called DAL.h and inside it a declaration of a function called OpenFile, this function is implemented in DAL.c.

I am trying to include DAL.h to my A project and use the OpenFile but I am receiving the following error: unresolved external symbol _OpenFile

I do understand that the compiler failed to find the implementation of OpenFile.

My question is what is the best practice in a case like the one described here ?

Should I "Add existing item" and add DAL.c to my A project ? (This fixes the error ..)

I did try to add the folder containg DAL.c to "Additional source folders" but that did not help.

Thanks a lot, Michael.

هل كانت مفيدة؟

المحلول

For you to use the compiled code of the OpenFile function, it will need to exist somewhere.

You seem to have two options:

1) If you want the compiled code to be part of your binary, you will need to include the source file so it can be compiled as part of your project.

2) If you don't want it to be built into your project, and from the sound of it you don't as you say it's "common code that should be shared among different projects", the "Framework project" should compile into a library. In which case you will need to include just the DAL.h header file, and import the "Framework project" library into your project so that your project can link the OpenFile call to the implementation in the library.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top