Click here to Skip to main content
15,894,896 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
See more:
<pre lang="c++"><pre lang="c++">
C++
I wrote Smaple Boost logger code,when i compiled this code,only .DLL file Created,but .Lib is not generated,can anyone help me,how to generate .Lib for this code to work Multi dependency projects.
 Project 1 contain Two file Logger.h and Logger.cpp
---------------------------------------------
 Sample Code 
-----------------
Logger.h
------
<pre>#pragma once
#include<crtdefs.h>
#include<boost/log/expressions.hpp>
#include<boost/log/expressions/formatters/named_scope.hpp>
#include<boost/log/sources/global_logger_storage.hpp>
#include<boost/log/support/date_time.hpp>
#include<boost/log/trivial.hpp>
#include<boost/log/utility/setup.hpp>
#include<string.h>
#include"Binary_Export.h"

#include <boost/log/sinks/debug_output_backend.hpp>
#define FILE (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
#define INFO   BOOST_LOG_SEV ( my_logger::get(), boost::log::trivial::info) << "|" << FILE<< "| " <<" "<<"|"<< __LINE__ << "| "<<__FUNCSIG__

#define WARN  BOOST_LOG_SEV( my_logger::get(), boost::log::trivial::warning) <<  "|" << FILE<< "| " <<" "<<"|"<< __LINE__ << "| "<<__FUNCSIG__
#define ERROR BOOST_LOG_SEV(my_logger::get(), boost::log::trivial::error) <<  "|" << FILE<< "| " <<" "<<"|"<< __LINE__ << "| "<<__FUNCSIG__

#define SYS_LOGFILE   "C:\\Users\\janardhanreddyn\\Documents\\LogFile\\DLL.log"

//Narrow-char thread-safe logger.
 typedef   boost::log::sources::severity_logger_mt<boost::log::trivial::severity_level>   logger_t;

//declares a global logger with a custom initialization
BOOST_LOG_GLOBAL_LOGGER( my_logger, logger_t);



Logger.Cpp
----------
#include"Simple_Logger.h"
namespace logging = boost::log;
namespace sinks = boost::log::sinks;
namespace src = boost::log::sources;
namespace expr = boost::log::expressions;
namespace attrs = boost::log::attributes;
namespace keywords = boost::log::keywords;
//Defines a global logger initialization routine
BOOST_LOG_GLOBAL_LOGGER_INIT(my_logger, logger_t)
{
	logger_t lg;

	logging::add_common_attributes();

	logging::add_file_log(
		keywords::file_name = SYS_LOGFILE,
		keywords::rotation_size = 1024 * 1024 * 20,    // megabytes
		keywords::time_based_rotation = boost::log::sinks::file::rotation_at_time_point (0, 0, 0),
		keywords::auto_flush = true,
		keywords::format = (
		expr::stream<<expr::format_date_time <boost::posix_time::ptime> ("TimeStamp", "%d-%m-%y %H:%M:%S")
		<< " [" << expr::attr <boost::log::trivial::severity_level> ("Severity") << "]: "
		<< expr::smessage

		)
		);

	logging::add_console_log(
		std::cout,
		keywords::format = (
		expr::stream <<"|"<< expr::format_date_time <boost::posix_time::ptime> ("TimeStamp", "%d-%m-%y %H:%M:%S")<<"|"
		<< " [" << expr::attr <boost::log::trivial::severity_level> ("Severity") << "]: "
		<< expr::smessage

		)

		);

	logging::core::get()->set_filter
		(
		logging::trivial::severity >= logging::trivial::info
		);

	return lg;
}
C++



What I have tried:

When I use above code in ProjectB, It was generated .Dll file,if i want to use above code in projectB,I need .Lib file.

ProjectB file Winfactory.h and Win_defination.cpp
---------------------------------------------------
Winfactory.h
---------------
#include"Factory.h"
#include"tfexports1.h"

class TF_API1 DWinfactory:public AFactory
{
public:
	DWinfactory();
	void Func();



};


Win_defination.cpp


#include"Winfactory.h"
DWinfactory::DWinfactory()
{



}
void DWinfactory:: Func()
{

	INFO<<Derived Func";         //Info used from Project1

}
Posted
Updated 31-Jan-17 0:28am
v2
Comments
Suvendu Shekhar Giri 31-Jan-17 5:32am    
Not Clear!
What exactly is the issue?
janardhan2104 31-Jan-17 6:11am    
Hi Shekhar,

I want to use projectA code into projectB,i want to export projectA code To ProjectB,to generate .lib file,i dont know ,which one i have to export,can you help me.

This looks like much the same issue as your previous question, posted yesterday.
See Walkthrough: Creating and Using a Dynamic Link Library (C++)[^].
 
Share this answer
 
v2
Comments
janardhan2104 31-Jan-17 6:51am    
Hi Richard,i wrote ProjectA code using third party libraries,in this case ,what are things do i have to export from projectA to ProjectB.
Richard MacCutchan 31-Jan-17 7:44am    
Follow the link I gave you above. It explains in clear detail the proper way to create a DLL.
Quote:
When I use above code in ProjectB, It was generated .Dll file,if i want to use above code in projectB,I need .Lib file.
Have a look at the output folder of your DLL project. It should contain the DLL and LIB files.

Then add the LIB file name to the dependant project or use
#pragma comment(lib, "lib-file-name")
in one of your source files (see comment (C-C++)[^]). The path for the lib file can be specified explicitely, by adding it to the project settings (library file pathes), or omitted when the lib file is copied to a path that is parsed for library files.

[EDIT]
See also Walkthrough: Creating and Using a Dynamic Link Library (C++)[^] and
Walkthrough: Creating and Using a Static Library (C++)[^]
[/EDIT]
 
Share this answer
 
v3
Comments
janardhan2104 31-Jan-17 6:46am    
Hi Jochen, I think ,for generating .Lib file, do we have export anything from projectA to projectB.In my project .lib not genearated.
Jochen Arndt 31-Jan-17 6:56am    
I don't know which VS version you are using, how you have setup your DLL project, and if you want static linking.

But I have updated my solution with MSDN links on how to create and use DLLs and LIB files.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900