473,398 Members | 2,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Static library issue

Hello
I have created what you would think would be the simplest of static
libraries, and still I cannot get it to link correctly.
In the static library (main.c) I have:

long __cdecl getnum(long testinput)
{

return 42;
}

and in the console app I have to test it, I have:

extern long __cdecl getnum(long testinput);
long _tmain(long argc, _TCHAR* argv[])
{
printf("number is %d", getnum(7));

}

I have the output .lib file of the first project added to the additional
linker dependencies in project properties, and the static library project's
output folder in the additional include directories for the test project.
Yet I get the error

libtest.obj : error LNK2019: unresolved external symbol "long __cdecl
getnum(long)" (?getnum@@YAJJ@Z) referenced in function _main
Debug/libtest.exe : fatal error LNK1120: 1 unresolved externals

Nov 17 '05 #1
1 1117
Bonj wrote:
Hello
I have created what you would think would be the simplest of static
libraries, and still I cannot get it to link correctly.
In the static library (main.c) I have:

long __cdecl getnum(long testinput)
{

return 42;
}

and in the console app I have to test it, I have:

extern long __cdecl getnum(long testinput);
long _tmain(long argc, _TCHAR* argv[])
{
printf("number is %d", getnum(7));

}

I have the output .lib file of the first project added to the additional
linker dependencies in project properties, and the static library project's
output folder in the additional include directories for the test project.
Yet I get the error

libtest.obj : error LNK2019: unresolved external symbol "long __cdecl
getnum(long)" (?getnum@@YAJJ@Z) referenced in function _main
Debug/libtest.exe : fatal error LNK1120: 1 unresolved externals


It looks like you have compiled your library module as a C program and
your main module as a C++ program. The compiler does different name
"decoration" for these so the linker is seeing two different names.

In your main program the function name getnum has been decorated as
?getnum@@YAJJ@Z and in the library it's probably _getnum.

You can fix this by changing getnum.c to getnum.cpp so that it compiles
as C++.

Norm

--
--
To reply, change domain to an adult feline.

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: adeht | last post by:
In his book, "Modern C++ Design", Andrei Alexandrescu presents a Generic Object Factory class (Loki::Factory). One of its advantages (also mentioned in the book) is being able to register the...
1
by: rahul | last post by:
Hi, I am working on developing a C++ application and caught with a strange issue: I am having 4 dynamic libraries for e.g. a.dll, b.dll, c.dll and d.dll. Each of these is linked with a static...
5
by: A.M | last post by:
Hi, I have i utility class contains static functions (and also members) I usually use in may applications. Can i have a static like constructor so any time the app starts, The constructor...
8
by: Robert A Riedel | last post by:
I have an application that requires a DLL and an executable that uses the DLL, both of which were implemented in Visual C++ using unmanged code. Both the executable and the DLL are linked with...
7
by: Adam | last post by:
I have a managed cpp wrapper. Im using this in a native dll as a static variable. I need to free this library when the dll is done being used. The perfect place to do this is DllMain for...
6
by: Bran Kelly | last post by:
Hi, I am running into something I haven't ever encountered before. I have a static instance of a class declared in a cpp file, which seems to be optimized (or for some other reason) out of...
14
by: Jeroen | last post by:
Hi all, I've got a question about writing a library. Let me characterize that library by the following: * there is a class A which is available to the user * there is a class B that is used...
1
TRScheel
by: TRScheel | last post by:
Platform: Windows Vista Language: ASPX / C# I am trying to make a business library for where I work, and I have everything figured out and done except for the ObjectDataSource portion. If any...
5
by: Michael Oswald | last post by:
Hello all, I'm working on a project where I came across some situations, where the GUI library works with normal C callbacks. The code has been implemented by many people, so I came across...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.