Find unresolved external symbol using similar project that builds fine - visual-studio-2010

I have two C projects that pull in the same library.
One project compiles and links fine, the other gets an "unresolved external reference" linker error for a symbol referenced inside a function which both projects call from the same static library.
As far as I can tell, all the linker and code generation properities of importance are equal between the two.
Is there a way to use the working project, to figure out where the linker in THAT project finds the symbol? I've been using trial and error, including more and more of the libraries from one project into the other with no success.

I found what I wanted! In the Project Properties, under Linker->Debugging, there is an option named "Generate Map File". This can be done on the command-line with /MAP.
The generated map file gets the same name as the project (by default) with .map as file extension. It is a text file containing, among other things, the library name where each symbol is defined.
Using the map file for my project that builds, I was able to quickly find the definition of the symbol missing from my broken project.

Related

LNK2019 Unresolved Symbol Even When The Linkage Exists

PLATFORM
Visual Studio 2010 Proffesional
MY PROBLEM
I have a solution called solution A. I have projects 'a' (static library containing internal and external header and source files) and 'b' (executable to see if 'a' functions can be used).
I intend to use static library 'a' functionality in another executable project 'c' which is in a different Solution C. What I have done is the following:
1) Added the static library folder (relative path) to the Include Directories section in my 'c' project properties (both debug and release configurations).
2) Checked the intellisense messenger to see whether or not the imports were successful.
Before I build solution C, everything was fine. However, as soon as I build it popped LNK2019 error because there is a function foo()that seemed to be unresolved. The (reported) function signatures are:
extern void foo(params);
extern void bar(void);
Just to remind the readers, foo(params) function is in static library 'a' in Solution A.
The error message I got was:
error LNK2001: unresolved external symbol _foo
error LNK2001: unresolved external symbol _bar
MY digagnosis so far
The obvious diagnosis would be that:
1) the function signature reported seem to have a mismatch with my orignal one (I checked using real man's find and replace tool in visual studio; there is no mismatch).
2) Check for any include guards that is blocking it (I have checked once again, but it doesn't have any that will cause this problem).
The one things that I need to mention is that exec. project b in Solution 'C' can use foo and bar in static library a easily. That may be because they are in the same solution and by simply adding the project directory to Include Directories in the project b properties will do the job. But when I try to use it in a different solution, it is breaking down. I did a full clean and rebuild of the solution, but no luck.
I am starting to think that it cannot find the definition in the same header file and gets confused. Although the definition is in the identically-named source file, it may still get confused.
I am struggling to find a solution to this without having a full modification. Does anyone know what to do?
I think I solved this problem by simply using "Add Reference" by right-clicking on the executable project where I was using it. However, I still had to manually import the static library project 'a' into the foreign solution C so that the referencing can be made.
I know it is not probably a good way of doing things, but it is definitely safer and I am pretty sure that it is going to work - one way or the other.

Boost in VS2010 Express - redefinition and invalid calling convention errors

I am using VS2010 Express and just installed Boost v1_47. I have added the 'include' folder to 'additional include folders' option, and also the 'lib' folder to the 'additional libraries' option in VS.
Then, I included boost/regex.hpp in one of my files, but actually wrote no code using boost yet. However, when building the solution I get lots of error messages, coming in two flavours:
Redefiniton errors, such as:
1>D:\boost\boost_1_47\boost/detail/interlocked.hpp(83): error C2373: '_InterlockedCompareExchangePointer' : redefinition; different type modifiers
1> C:\Program Files\Microsoft SDKs\Windows\v7.1\include\winnt.h(2597) : see declaration of '_InterlockedCompareExchangePointer'
Invalid calling convention errors (lots of these), such as:
D:\boost\boost_1_47\boost/regex/v4/regex_traits_defaults.hpp(271): error C3641: 'boost::re_detail::global_lower' : invalid calling convention '__cdecl ' for function compiled with /clr:pure or /clr:safe
Note: I haven't explicitly included winnt.h in any of my source/header files, and have tried de-activating pre-compiled headers and removing the stdafx.h includes, but it didn't solve the problem.
What's going on?
Thanks in advance
You have to make sure that you compile your program with the same settings as boost.
It seems like you used the wrong project template (CLR something) to create your application project.
You could try to modify the properties of your existing project to make it compatible with boost, but the CLR ... projects have lots of incompatible property values set by default, so i think the easiest way would be to create a new project from scratch (and import your existing code).
You should use the "Empty Project" template and create a new project, and then add your existing source and header files to it, and add the boost include path again, and add any required boost .lib files to Project Properties > Linker > Input > Additional Dependencies (Most boost libraries work out of the box without adding anything to linker inputs because they are header only, so you might not need to add any .libs).
Boost is a C++ required, designed to be consumed by C++ code, not C++/CLI code, thus it can only be used with native C++ classes, and most boost headers will produce headers when included in a source file which contains C++/CLI code.

Makefiles in Microsoft Visual Studio 2010

I am getting some linking errors during the compilation of C project in Microsoft Visual Studio 2010.I am getting the following errors:
error LNK2019: unresolved external symbol _CreateRelation referenced in function _main
The CreateRelation is one of the functions in my project. Following are my questions:
I think it is some dependencies problem.How would I set those dependencies rule in the IDE?
could you please tell me, is it always possible to build a project and set the linking rule, how much it is larger, without using makefile?
[EDIT]
relation.h
void createRelation(LIST);
mainfile.c
#include relation.h
#include xyz.h
.
.
.
int main(){
LIST Relation1;
some codes //
createRelation(Relation1);
some code //
}
The function creatRelation() is defined in the realation.h.
EDIT 2
In the function containing main
There are a few ways to set the dependencies for the build process.
If the code you are referencing is in a sub-project you can simply tell VS the build-dependencies. You do that by right-clicking on the project and select project dependencies. Then you can check all projects that should be built before this project is being built.
Another nifty feature of VS2010 are Property Sheets. In older versions of VS you had to tell the compiler the include path and the lib-path for every project. Now you can create property sheets for every library you are using and then simply adding them to your project. This way you only have to create a property sheet once and can use it in many projects.
So if the code is in another project that is not a sub-project you have to set the lib-path and include-path via those property sheets. You can display the property sheets used by your project by clicking View->Additional Windows->Property Manager
If you are not referencing to any external projects. This problem is most likely caused by you not implementing a function you declared. So the compiler knows about the function-prototype and doesn't complain but the linker can't find an implementation of the symbol.
I hope that helps
-- edit --
Since you said that the implementation is in the same file as the main-function I would suspect that the signature of the declared and defined function do not match. Are you getting any warnings about implicit function declaration?
Is that a copy-paste error?
CreateRealtion(x); vs. CreateRelation(x);

Including one Xcode project in another -- linker errors

I am trying to do this, and running into problems. The parent project needs to access the class SettingsViewController from the child project. I have put the child project path into my header search paths. Everything compiles OK, but I get linker errors, as follows:
Undefined symbols: "_OBJC_METACLASS_$_SettingsViewController",
referenced from:
_OBJC_METACLASS_$_StatisticsViewController in StatisticsViewController.o "_OBJC_CLASS_$_SettingsViewController",
referenced from:
objc-class-ref-to-SettingsViewController in SelectionViewController.o
_OBJC_CLASS_$_StatisticsViewController in StatisticsViewController.o ld: symbol(s) not found collect2: ld
returned 1 exit status
How can I fix this?
I assume the child project is a static library. Currently, your parent project knows how to find the header files of the child project (otherwise it wouldn't compile), but it doesn't know that it has to link to the library (.a) file of the child project.
You should probably add the library file to Targets > {your app} > Link Binary with Libraries. Furthermore, you probably need to add the linker flags -ObjC and possibly -all_load.
There are many detailed descriptions on the net, e.g. Build iPhone static library with Xcode.
Update:
If it's not a static library, then it's a rather strange project setup. The best thing you can do is to add the shared files (.h and .m) to both projects. They will then be independently compiled in both projects. That should work if you have few shared files.
But I recommend anyway to use a project setup with a static library. It nicely works if you properly set it up. I'm successfully using it. And - as I've told before - there a several good descriptions on the net how to set it up.
You may be missing a framework. Can't really tell from what you have posted here though.
I know this is very old but might be helpful for others.
You need to setup the included project in Target Dependencies in "Build Phases" to get the included projet to be compiled and you also should add the static library of the included project in the "Link Binary with Libraries".
Click on your Target->Build Phases and set these up.
Undefined symbols
Undefined symbols is a linker error
1.Check if you have added a library or framework
Project editor -> select a target -> General -> Frameworks, Libraries, and Embedded Content(Linked Frameworks and Libraries)
//or
Project editor -> select a target -> Build Phases -> Link Binary With Libraries
2.If you try to use Swift code from Objective-C
Add empty .swift file to the Objective-C project. When Xcode ask press Create Bridging Header

Problem with static library in C++

I'm trying to use a static library created by me in Visual C++ 2005 (unmanaged C++). I declare one function "int myF(int a);" into a .h file, I implement it in a .cpp file, I compile it - the .lib file is produced.
I create a new project (a separate solution) in VC++ 2005 (also native C++), I add the paths for the include file and the lib file; when I invoke the function myF the linker reports an error: "error LNK2019: unresolved external symbol _myF referenced in function _main". if I create the client project in the same solution as the library project and then add a reference to the library projects, it works, but I'm not going to implement everything like this, but rather to add external libraries to my projects...
What is wrong?
Thank you.
You need to also include the actual .lib file in your 2nd project (not just the path to it).
There should be an option in the linker settings to do this.
It is not sufficient to list the folder in which MyStatic.lib can be found. You have to explicitly tell the linker that Dependant.vcproj is using MyStatic.lib.
In VS2005 you do this by project properties->Linker->Input->Additional Dependencies. You can also sprinkle some preprosessor stuff in the .h file to tell the compiler to tell the linker to use MyStatic.lib.
Edit:
The preprocessor magic goes like this
#pragma comment(lib, "MyStatic.lib")
(EDIT: This was a response to the question of getting the /NODEFAULTLIB error in link phase which has now been deleted... shrug)
You are mixing compiler settings if your are getting the defaultlib error. For example, if you build your library in debug and the build your main in release, you will get this error since they are built to use different versions of the CRTL. This can also happen if you use different settings for linking with the C Runtime as a object library or as a DLL. (See the C/C++ options, the "Code Generation" section, under the "Runtime Library" setting)
In many projects there isn't much you can do if you can't correct the settings of the library (for example, 3rd party libraries). In those cases you have to use the /NODEFAULTLIB switch which is a linker option in the "Input" section called "Ignore Specific Library".
But since you are in control of both the main and the library, build a debug and a release version of your LIB file or make sure your "C/C++;Code Generation;Runtime Library" settings match in both projects.
Try setting additional dependencies in the linker input for a project properties.

Resources