473,412 Members | 3,763 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,412 software developers and data experts.

Problems with ....hmm, linker perhaps

Dear all,

IMO the following program is legal and should compile.

//***** code start *********
// Definition of class A
template <typename T> struct A
{
typedef T value_type;
};

// Definition of class B
template <typename> struct B {};

// Function foo
// returntype important !
template <typename T>
B<typename T::value_type> foo()
{
return B<typename T::value_type>();
};

int main()
{
typedef B< int >( * ptr )(); // Function pointer

ptr foo_ptr = foo< A<int> >; // Initialization of function pointer

return 0;
}
//***** code end *********

It builds fine with g++ and MSVC7.1, but the latter one fails linking:

unresolved external symbol "struct B<int> __cdecl foo<struct A<int> >(void)"
(??$foo@U?$A@H@@@@YA?AU?$B@H@@XZ) referenced in function _main

what I do not really understand. It is getting a lit more weird now. If I
change

ptr foo_ptr = foo< A<int> >;

to

ptr foo_ptr ;
foo_ptr = foo< A<int> >;

it compiles and links fine as well with MSVC 7.1.

Before I blame anyone, I want to ask if I overlooked something? IMO the code
is fine.

Regards,
Patrick

Jul 22 '05 #1
13 1268
If I change

ptr foo_ptr = foo< A<int> >;

to

ptr foo_ptr ;
foo_ptr = foo< A<int> >;

it compiles and links fine as well with MSVC 7.1.

Well, without scrutanizing your code too much, the only difference in the
above is that the former calls a constructor, while the latter calls the
default constructor and then calls operator=.
-JKop
Jul 22 '05 #2
Patrick Kowalzick wrote:
Dear all,

IMO the following program is legal and should compile.

//***** code start *********
// Definition of class A
template <typename T> struct A
{
typedef T value_type;
};

// Definition of class B
template <typename> struct B {};

// Function foo
// returntype important !
template <typename T>
B<typename T::value_type> foo()
{
return B<typename T::value_type>();
};

int main()
{
typedef B< int >( * ptr )(); // Function pointer

ptr foo_ptr = foo< A<int> >; // Initialization of function pointer

return 0;
}
//***** code end *********

It builds fine with g++ and MSVC7.1, but the latter one fails linking:

unresolved external symbol "struct B<int> __cdecl foo<struct A<int> >(void)"
(??$foo@U?$A@H@@@@YA?AU?$B@H@@XZ) referenced in function _main

what I do not really understand. It is getting a lit more weird now. If I
change

ptr foo_ptr = foo< A<int> >;

to

ptr foo_ptr ;
foo_ptr = foo< A<int> >;

it compiles and links fine as well with MSVC 7.1.

Before I blame anyone, I want to ask if I overlooked something? IMO the code
is fine.

Regards,
Patrick


compiles and links fine with Sun Studio 9...
Jul 22 '05 #3
"Patrick Kowalzick" <Pa***************@cern.ch> wrote in message
news:cl**********@sunnews.cern.ch...
Dear all,

IMO the following program is legal and should compile.


I concur with your opinion. I tested and verified that VC7.1 does not. I
think it's not a problem with the linker though, it looks as if the compiler
isn't instantiating the foo<A<int> > template, so when the linker looks for
it, it finds nothing.

I also tested this under Visual C++ 2005 (VC8) beta 1
(http://lab.msdn.microsoft.com/vs2005/), and it compiles and links fine,
which seems to suggest this is indeed a bug in VC7.1 which has been fixed
for VC8.

--
Unforgiven
Jul 22 '05 #4
Dear Unforgiven,
IMO the following program is legal and should compile.
I concur with your opinion. I tested and verified that VC7.1 does not. I
think it's not a problem with the linker though, it looks as if the

compiler isn't instantiating the foo<A<int> > template, so when the linker looks for it, it finds nothing.

I also tested this under Visual C++ 2005 (VC8) beta 1
(http://lab.msdn.microsoft.com/vs2005/), and it compiles and links fine,
which seems to suggest this is indeed a bug in VC7.1 which has been fixed
for VC8.


Thanks a lot.

So it seems that I have to search a workaround for my application :(, which
has a little bit different structure compared to the testcase.

Patrick
Jul 22 '05 #5
Hi JKop,
If I change

ptr foo_ptr = foo< A<int> >;

to

ptr foo_ptr ;
foo_ptr = foo< A<int> >;

it compiles and links fine as well with MSVC 7.1.

Well, without scrutanizing your code too much, the only difference in the
above is that the former calls a constructor, while the latter calls the
default constructor and then calls operator=.


[answer for JKop]
Bullshit.

[answer for the rest]
I doubt that for function pointers constructors must be called. Is this
compiler dependent? Whats the terminology for built-in types?

Reagrds,
Patrick
Jul 22 '05 #6
> compiles and links fine with Sun Studio 9...

Thx.
Jul 22 '05 #7
[answer for JKop]
Bullshit.

Perhaps I should be more general:
A) AnyClass blah = some_expression;

This calls a contructor, supplying "some_expression" as an argument.
B) AnyClass blah; blah = some_expression;
This calls the default constructor. It then calls operator=.
Use your own intelligence to see what I'm getting at.
-JKop
Jul 22 '05 #8
In message <5z*******************@news.indigo.ie>, JKop <NU**@NULL.NULL>
writes
[answer for JKop]
Bullshit.

Perhaps I should be more general:
A) AnyClass blah = some_expression;

This calls a contructor, supplying "some_expression" as an argument.
B) AnyClass blah; blah = some_expression;
This calls the default constructor. It then calls operator=.
Use your own intelligence to see what I'm getting at.


What is the type of foo_ptr?

--
Richard Herring
Jul 22 '05 #9
> > [answer for JKop]
Bullshit.

Yep.

Perhaps I should be more general:
A) AnyClass blah = some_expression;

This calls a contructor, supplying "some_expression" as an argument.
B) AnyClass blah; blah = some_expression;
This calls the default constructor. It then calls operator=.


You are talking about classes, don't you?
See the OP, I was talking about function pointers.

Regards,
Patrick

Jul 22 '05 #10
Patrick Kowalzick wrote in news:cl**********@sunnews.cern.ch in
comp.lang.c++:
int main()
{
typedef B< int >( * ptr )(); // Function pointer

ptr foo_ptr = foo< A<int> >; // Initialization of function pointer

return 0;
}
//***** code end *********

It builds fine with g++ and MSVC7.1, but the latter one fails linking:

unresolved external symbol "struct B<int> __cdecl foo<struct A<int>
(void)" (??$foo@U?$A@H@@@@YA?AU?$B@H@@XZ) referenced in function

_main


This is a bug in MSVC 7.1, Its "forgoten" to do the implicit
instantiation of foo< A< int > >.

I haven't seen it in precisly this context (taking a function pointer)
but in a few other's I have.

As a minor data point I compiled with:

cl -nologo -Za -Zc:forScope,wchar_t -EHsc -O1 -ML -Tptest.cpp

and msvc *didn't* exhibit the problem, but if I compiled:

cl test.cpp

I got the unresolved external, I don't know which combination of
option's achived this turnaround or why.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #11
Patrick Kowalzick wrote:
...
int main()
{
typedef B< int >( * ptr )(); // Function pointer

ptr foo_ptr = foo< A<int> >; // Initialization of function pointer

return 0;
}
//***** code end *********

It builds fine with g++ and MSVC7.1, but the latter one fails linking:

unresolved external symbol "struct B<int> __cdecl foo<struct A<int> >(void)"
(??$foo@U?$A@H@@@@YA?AU?$B@H@@XZ) referenced in function _main
...


Seems to be a compiler problem. Try using the address-of operator explicitly

ptr foo_ptr = &foo< A<int> >;

I remember that sometimes it helped to solve similar problems in MSVC++
6, but I don't know whether it will help in MSVC++ 7.

Explicit instantiation will probably also solve the problem, but that
would be a high-maintenance solution.

--
Best regards,
Andrey Tarasevich
Jul 22 '05 #12
There is a known bug in visual studio 6 when defining
function templates that don't have the templated variables
in their signature.
Jul 22 '05 #13
Hi Andrey,
Seems to be a compiler problem. Try using the address-of operator explicitly
ptr foo_ptr = &foo< A<int> >;
same problem,...
I remember that sometimes it helped to solve similar problems in MSVC++
6, but I don't know whether it will help in MSVC++ 7.

Explicit instantiation will probably also solve the problem, but that
would be a high-maintenance solution.


but while I get around it like this:

ptr foo_ptr;
foo_ptr = &foo< A<int> >;

it is ok for now :). I documented in my code as a bug. Shall be enough....

Thanks,
Patrick
Jul 22 '05 #14

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

Similar topics

13
by: SpaceCowboy | last post by:
I recently got into a discussion with a co-worker about using enums across a dll interface. He wanted to use chars instead, argueing that depending on compiler settings the size of an enum could...
15
by: Rob Ratcliff | last post by:
I'm compiling the latest version of a CORBA ORB called MICO on a Cray X1. It makes heavy use of templates and namespaces. Up until the link step, the C++ source code compiled flawlessly. But, when...
0
by: Tom McDermott | last post by:
I am having linker errors : error LNK2022: metadata operation failed (80131188) : Inconsistent field declarations in duplicated types This code linked sucessfully in C++.NET 2002, but does...
0
by: DotNetJunkies User | last post by:
Hi! I got some huge problems trying to use a C/C++ package (originally from a gcc environment) into a library in VS.NET 2003 and finally linked and used by a C# windows service. Basicly nothing...
5
by: Tanja Krammer | last post by:
Hi experts, is it possible to disable linker warnings (i.e. LNK4204)? Thanx
4
by: Bit byte | last post by:
I have a project that I normally build (without problems) from the DevStudio IDE. However, I have embarked on automating all my builds (this test project being one of several). The project...
1
by: Juan Alvarez | last post by:
hi, everyone, I have a serious problem here, i need to make a program using Regular Expressions in C in Dev-C++. I found some tutorials but all the links are broken :S i have 5 days looking for...
2
by: iCoder | last post by:
hi All, This is my first post.. I am trying to understand how #include works... I wrote a simple multi file project like this in C::B. ///// MyFunc.h /////////// #ifndef...
20
by: Aek | last post by:
We recently moved our large codebase over from VS7 to 8 and found that we now get access violations in atexit calls at shutdown when debugging the application in VS2005. This occurs in static...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.