Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2010 - linker errors in stand-alone functions

I have two projects in my solution; one which builds a static lib, another which uses it and tests it.

I've got these linkers errors (2019) when using this function in my test app... yet I can link other declared stuff (soley classes) without problem.

The test-app is dependent on the static lib, and it has reference to it as well so it should link (I only get that linker error as well)

Why is this? Am I missing something? I can't think of anything else that couldve gone wrong.

PortableTime.h

#ifndef _PORTABLE_TIME_H
#define _PORTABLE_TIME_H

#if defined _WIN32 || _WIN64
#include <WinSock2.h>
#else
#include <time.h>
#endif

#include <stdint.h>

uint64_t GetTimeSinceEpoch();

#endif

PortableTime.cpp

#include "PortableTime.h"

uint64_t GetTimeSinceEpoch()
{
    #if defined _WIN32 || _WIN64
        return (uint64_t)timeGetTime();
    #else
        struct timeval tv;
        gettimeofday(&tv, 0); 
        return (((uint64_t)tv.tv_sec)*(uint64_t)1000) + (((uint64_t)tv.tv_usec)/(uint64_t)1000);
    #endif
}
like image 631
KaiserJohaan Avatar asked Feb 02 '12 19:02

KaiserJohaan


People also ask

How to resolve linker error in Visual Studio?

The object file or library that contains the definition of the symbol isn't linked. In Visual Studio, make sure the object file or library that contains the symbol definition is linked as part of your project. On the command line, make sure the list of files to link includes the object file or library.

How to solve linker error c++ undefined symbol?

So when we try to assign it a value in the main function, the linker doesn't find the symbol and may result in an “unresolved external symbol” or “undefined reference”. The way to fix this error is to explicitly scope the variable using '::' outside the main before using it.

What does unresolved external symbol mean?

Unresolved external references occur when the symbol for a function or global variable is referenced in a program, but none of the object files or libraries specified in the link step contain a definition for that symbol.


1 Answers

timeGetTime function requires Winmm.lib library, so you have to specify it among additional dependencies.

Configuration Properties -> Linker -> Input -> Additional Dependencies.

like image 105
LihO Avatar answered Sep 18 '22 01:09

LihO